InvokeAI/invokeai/app/services
psychedelicious 421440cae0 feat(nodes): exhaustive graph validation
Makes graph validation logic more rigorous, validating graphs when they are created as part of a session or batch.

`validate_self()` method added to `Graph` model. It does all the validation that `is_valid()` did, plus a few extras:
- unique `node.id` values across graph
- node ids match their key in `Graph.nodes`
- recursively validate subgraphs
- validate all edges
- validate graph is acyclical

The new method is required because `is_valid()` just returned a boolean. That behaviour is retained, but `validate_self()` now raises appropriate exceptions for validation errors. This are then surfaced to the client.

The function is named `validate_self()` because pydantic reserves `validate()`.

There are two main places where graphs are created - in batches and in sessions.

Field validators are added to each of these for their `graph` fields, which call the new validation logic.

**Closes #4744**

In this issue, a batch is enqueued with an invalid graph. The output field is typed as optional while the input field is required. The field types themselves are not relevant - this change addresses the case where an invalid graph was created.

The mismatched types problem is not noticed until we attempt to invoke the graph, because the graph was never *fully* validated. An error is raised during the call to `graph_execution_state.next()` in `invoker.py`. This function prepares the edges and validates them, raising an exception due to the mismatched types.

This exception is caught by the session processor, but it doesn't handle this situation well - the graph is not marked as having an error and the queue item status is never changed. The queue item is therefore forever `in_progress`, so no new queue items are popped - the app won't do anything until the queue item is canceled manually.

This commit addresses this by preventing invalid graphs from being created in the first place, addressing a substantial number of fail cases.
2023-10-05 09:32:29 +11:00
..
config feat(images): add png_compress_level config 2023-10-05 08:24:52 +11:00
invocation_cache fix(backend): remove extra cache arg (#4698) 2023-09-26 10:03:48 -04:00
models isort wip 2023-09-12 13:01:58 -04:00
session_processor replace case statements with if/else to support python 3.9 2023-09-25 18:33:39 +10:00
session_queue feat(nodes): exhaustive graph validation 2023-10-05 09:32:29 +11:00
shared feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
__init__.py all files migrated; tweaks needed 2023-03-03 00:02:15 -05:00
board_image_record_storage.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
board_images.py isort wip 2023-09-12 13:01:58 -04:00
board_record_storage.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
boards.py isort wip 2023-09-12 13:01:58 -04:00
default_graphs.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
events.py fix: canvas not working on queue 2023-09-20 09:57:10 -04:00
graph.py feat(nodes): exhaustive graph validation 2023-10-05 09:32:29 +11:00
image_file_storage.py chore: isort 2023-10-05 08:24:52 +11:00
image_record_storage.py sort by starred and then created_at to get board cover image 2023-10-04 08:54:47 +11:00
images.py feat(backend): selective invalidation for invocation cache 2023-09-20 18:26:47 +10:00
invocation_queue.py fix: canvas not working on queue 2023-09-20 09:57:10 -04:00
invocation_services.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
invocation_stats.py isort wip 2023-09-12 13:01:58 -04:00
invoker.py fix: canvas not working on queue 2023-09-20 09:57:10 -04:00
item_storage.py Apply black 2023-07-27 10:54:01 -04:00
latent_storage.py feat(backend): selective invalidation for invocation cache 2023-09-20 18:26:47 +10:00
model_manager_service.py fix: canvas not working on queue 2023-09-20 09:57:10 -04:00
processor.py fix: canvas not working on queue 2023-09-20 09:57:10 -04:00
resource_name.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
sqlite.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
thread.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
urls.py feat: add multi-select to gallery 2023-08-03 11:46:59 +10:00