-
Notifications
You must be signed in to change notification settings - Fork 15
save_workgraph_data fails on non-JSON-serializable default values in @task.graph function signatures #767
Copy link
Copy link
Open
Description
Having implemented a custom serlaizer for Enum i.e.
[project.entry-points."aiida.data"]
"koopmans.aiida_quantumespresso.common.types.ElectronicType" = "aiida.orm.nodes.data.enum:EnumData"
the serialization does not carry over to save_workgraph_data. Specifically, when a @task.graph-decorated function has parameters with non-JSON-serializable defaults (e.g. Enum members), save_workgraph_data fails because it stores the full graph definition — including these defaults — as a node attribute via node.workgraph_data = wgdata, which triggers clean_value().
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida_workgraph/engine/workgraph.py", line 254, in on_create
save_workgraph_data(self.node, raw_inputs)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida_workgraph/utils/__init__.py", line 228, in save_workgraph_data
node.workgraph_data = wgdata
^^^^^^^^^^^^^^^^^^^
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida_workgraph/orm/workgraph.py", line 24, in setter
self.base.attributes.set(attribute_key, value)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida/orm/nodes/attributes.py", line 119, in set
self._backend_node.set_attribute(key, value)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida/storage/psql_dos/orm/nodes.py", line 248, in set_attribute
value = clean_value(value)
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida/orm/implementation/utils.py", line 102, in clean_value
return {k: clean_value(v) for k, v in value.items()}
~~~~~~~~~~~^^^
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida/orm/implementation/utils.py", line 102, in clean_value
return {k: clean_value(v) for k, v in value.items()}
~~~~~~~~~~~^^^
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida/orm/implementation/utils.py", line 102, in clean_value
return {k: clean_value(v) for k, v in value.items()}
~~~~~~~~~~~^^^
[Previous line repeated 2 more times]
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida/orm/implementation/utils.py", line 115, in clean_value
return clean_builtin(value)
File "/home/linsco_e/code/koopmans2/.venv/lib/python3.13/site-packages/aiida/orm/implementation/utils.py", line 95, in clean_builtin
raise exceptions.ValidationError(f'type `{type(val)}` is not supported as it is not json-serializable')
aiida.common.exceptions.ValidationError: type `<enum 'ElectronicType'>` is not supported as it is not json-serializable
...
aiida/orm/implementation/utils.py:95 clean_builtin
raise ValidationError(f'type `{type(val)}` is not supported as it is not json-serializable')
ValidationError: type `<enum 'ElectronicType'>` is not supported as it is not json-serializable
Is this a bug? Or have I not implemented the custom serializer correctly? We clearly want to be able to provide Enum members as defaults somehow...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels