Avinash Santhanagopalan
11/23/2023, 2:36 AMJenny
11/23/2023, 12:43 PMAvinash Santhanagopalan
11/28/2023, 12:08 PMMichał Augoff
11/30/2023, 3:14 AMfrom typing import Optional
from prefect import flow
from prefect.deployments import Deployment
from pydantic import BaseModel
class MySubModel(BaseModel):
a: int
class MyModel(BaseModel):
sub_model: Optional[MySubModel] = None
@flow
def my_flow(my_model: MyModel):
return
Deployment.build_from_flow(
flow=my_flow,
parameters={
"my_model": MyModel()
},
name="test",
).apply()
results in ⬇️ on 2.14.6Avinash Santhanagopalan
11/30/2023, 11:03 AMMichał Augoff
11/30/2023, 2:57 PMJenny
11/30/2023, 5:31 PMfrom typing import Optional
from prefect import flow
from pydantic import BaseModel, Field
class PydanticFieldsDefault(BaseModel):
str_field_default: Optional[str] = Field(
title="Title str_field_default", description="Description str_field_default"
)
@flow(log_prints=True)
def optional(pydantic_fields_default: PydanticFieldsDefault = PydanticFieldsDefault()):
print(pydantic_fields_default)
return pydantic_fields_default
if __name__ == "__main__":
optional.serve(name="print")
Jenny
11/30/2023, 5:31 PMJenny
11/30/2023, 5:34 PMMichał Augoff
11/30/2023, 5:36 PMMichał Augoff
11/30/2023, 5:38 PMMichał Augoff
11/30/2023, 5:56 PMfrom typing import Optional
from prefect import flow
from prefect.deployments import Deployment
from pydantic import BaseModel
class Person(BaseModel):
first_name: str
last_name: str
class Postcard(BaseModel):
sender: Optional[Person]
recipient: Person
text: str
@flow(log_prints=True)
def send_postcard(postcard: Postcard):
print(f"Sending {postcard.text} to {postcard.recipient} (sender: {postcard.sender})")
my_postcard = Postcard(
recipient=Person(first_name="My", last_name="Friend"),
text="Greetings from Prefect"
)
send_postcard(my_postcard)
Deployment.build_from_flow(
flow=send_postcard,
parameters={"postcard": my_postcard},
name="test",
).apply()
calling the flow directly with my_postcard
gives the expected result
10:54:41.429 | INFO | Flow run 'unique-bobcat' - Sending Greetings from Prefect to first_name='My' last_name='Friend' (sender: None)
But when I go to the UI of the deployment, I see, even though sender
should be optional:Jenny
11/30/2023, 6:03 PMMichał Augoff
11/30/2023, 6:08 PMJenny
11/30/2023, 6:40 PMMichał Augoff
12/07/2023, 7:26 PMrun_deployment
to successfully trigger a run.
Continuing with the postcard example above, when I run the flow locally, the optional sender parameter is correctly reported as null
(screen 1).
When I register the same exact flow as a deployment with default parameters matching the local run, the optional parameter gets translated to {}
(screen 2).
Even if I manually overwrite it to null
inside Quick run
to match parameters from the local run, it’s still gets passed to the triggered run as {}
and fails parameter validation (screen 3), so it’s impossible to run this deployment unless I provide the sender parameter as a valid Person
object which essentially makes that parameter requiredJenny
12/08/2023, 4:24 PM