Open aeisenbarth opened 7 months ago
Hey @aeisenbarth! That's for the reproducible example, I can confirm it also throws an error on my end.
I have 👀 on this!
Hey @aeisenbarth!
Did some digging, if you:
run_deployment(name=deployment_name, parameters=dict(parameters=parameters.model_dump()))
dict
'ing them:
run_deployment(name=deployment_name, parameters=parameters)
then I was able to get your provided example to run as expected. Do either of these seem satisfactory to you?
Thanks, that is an ingenious idea! The first one is ok for me.
@desertaxle @tardunge I am trying to run a simple spark-operator job on prefect server by following the instructions provided here: https://github.com/tardunge/prefect-spark-on-k8s-operator/blob/main/README.md. When I try to run the job locally (python3.11 job.py), I run into "prefect.exceptions.ScriptError: Script is attached below encountered an exception: TypeError("Object of type 'FieldInfo' is not JSON serializable")". Note: I am running the code inside a container.
Attaching simple reproducible code for the pydantic errors. `from pydantic import Field, version as pydantic_version from prefect.blocks.core import Block
class Bar(Block): interval_seconds: int = Field( default=5, description="The number of seconds to wait between application status checks.", ) b = Bar() print(f"{pydantic_version=}") if pydantic_version >= '2': print(b.interval_seconds) else: print(b.interval_seconds)`
Temporary Fix: I was able to workaround this issue 2 ways: 1) Pass the parameters directly without dict'ing them in app.py in the source package code. 2) Downgrading to pydantic 1.10 from 2.x in my image container makes it work without needing to make pydantic/dict changes in app.py.
Ideally, I would like to use the integration feature without making any modifications straight off the shelf.
First check
Bug summary
When a flow uses Pydantic 2 models and is run from a deployment, orjson fails to serialize them.
This is similar to https://github.com/PrefectHQ/prefect/issues/9536, except that parameters don't use a custom class, but a normal Pydantic model, which seems to be supported by Prefect. This issue is blocking the switch to Pydantic 2 for me.
Reproduction
Error
Versions
Additional context
prefect==2.16.3 # same for prefect==2.14.20, prefect==2.15.0 pydantic==2.6.3 # same for pydantic==2.0.0 orjson==3.9.15