|
4 | 4 |
|
5 | 5 | from PIL import Image
|
6 | 6 |
|
7 |
| -from invokeai.app.services.shared.graph import Graph |
8 | 7 | from invokeai.app.services.workflow_records.workflow_records_common import WorkflowWithoutIDValidator
|
9 | 8 |
|
10 | 9 |
|
@@ -95,8 +94,25 @@ def extract_metadata_from_image(
|
95 | 94 | # always store graphs as a stringified JSON Graph. So, we expect it to be a string here.
|
96 | 95 | if isinstance(graph_raw, str):
|
97 | 96 | try:
|
98 |
| - # Validate the graph JSON before storing it |
99 |
| - Graph.model_validate_json(graph_raw) |
| 97 | + # TODO(psyche): Due to pydantic's handling of None values, it is possible for the graph to fail validation, |
| 98 | + # even if it is a direct dump of a valid graph. Node fields in the graph are allowed to have be unset if |
| 99 | + # they have incoming connections, but something about the ser/de process cannot adequately handle this. |
| 100 | + # |
| 101 | + # In lieu of fixing the graph validation, we will just do a simple check here to see if the graph is dict |
| 102 | + # with the correct keys. This is not a perfect solution, but it should be good enough for now. |
| 103 | + |
| 104 | + # FIX ME: Validate the graph JSON before storing it |
| 105 | + # Graph.model_validate_json(graph_raw) |
| 106 | + |
| 107 | + # Crappy workaround to validate JSON |
| 108 | + graph_parsed = json.loads(graph_raw) |
| 109 | + if not isinstance(graph_parsed, dict): |
| 110 | + raise ValueError("Not a dict") |
| 111 | + if not isinstance(graph_parsed.get("nodes", None), dict): |
| 112 | + raise ValueError("'nodes' is not a dict") |
| 113 | + if not isinstance(graph_parsed.get("edges", None), list): |
| 114 | + raise ValueError("'edges' is not a list") |
| 115 | + |
100 | 116 | # Looks good, overwrite the fallback value
|
101 | 117 | stringified_graph = graph_raw
|
102 | 118 | except Exception as e:
|
|
0 commit comments