sdk-python
sdk-python copied to clipboard
Importing 3rd party package `ruamel.yaml` anywhere causes failure to validate workflow
To reproduce:
- Checkout https://github.com/temporalio/samples-python
-
poetry add ruamel.yaml
- Add
import ruamel.yaml
to the top ofhello/hello_activity.py
-
poetry run hello/hello_activity.py
This produces the error here: https://gist.github.com/adamh-oai/dfdb9b07b89bf3cee10da34ba2582805
Important parts:
File "/Users/adamh/.virtualenvs/temporalio-samples-G-Ux_4V2-py3.11/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 1132, in <module>
RoundTripRepresenter.add_representer(TimeStamp, RoundTripRepresenter.represent_datetime)
File "/Users/adamh/.virtualenvs/temporalio-samples-G-Ux_4V2-py3.11/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 135, in add_representer
cls.yaml_representers[data_type] = representer
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: unhashable type: '_RestrictedProxy'
The above exception was the direct cause of the following exception:
...
File "/Users/adamh/.virtualenvs/temporalio-samples-G-Ux_4V2-py3.11/lib/python3.11/site-packages/temporalio/worker/_workflow.py", line 118, in __init__
raise RuntimeError(f"Failed validating workflow {defn.name}") from err
RuntimeError: Failed validating workflow GreetingWorkflow
This behavior is surprising to me because the workflow/activity is not actually using the ruamel
package. The error persists if I move the workflow/activity to a separate module and wrap in a imports_passed_through
block. Wrapping the ruamel
import in this same block does resolve the error. It seems like the ruamel
import may have side effects on other modules. So, I have a workaround, but (short of disabling sandboxing entirely) I'm concerned that in a large codebase with unpredictable 3rd party libraries this will be a recurring issue.