Giuliano Mega

11/10/2022, 11:54 AM
Hello there! I'm having an issue with default parameters on a flow that uses pydantic validation. My flow looks something like:
class FlowParameters(BaseModel):
    requests_per_minute: int = 10
    ids: Optional[List[str]] = None

    description='Imports and enriches Entities.',
def token_pipeline(parameters: FlowParameters):
    new_entities = fetch_new_entities(parameters.ids), parameters.requests_per_minute)
If I call my flow from Prefect Cloud and pass it some parameters (run Custom), all runs smoothly. If, on the other hand, I try to run it with the default parameters, I get:
Validation of flow parameters failed with error: 
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/prefect/", line 275, in retrieve_flow_then_begin_flow_run
    parameters = flow.validate_parameters(flow_run.parameters)
  File "/usr/local/lib/python3.10/site-packages/prefect/", line 324, in validate_parameters
    raise ParameterTypeError.from_validation_error(exc) from None
prefect.exceptions.ParameterTypeError: Flow run received invalid parameters:
 - parameters: field required
Which is weird. Expected behavior would be having the flow run with default parameters. Can't seem to understand what I'm doing wrong from reading the docs, any ideas? 🙂

Ryan Peden

11/10/2022, 1:20 PM
Hi, Giuliano! It looks like you're providing a type for your parameter, but not a default value that gets assigned at runtime. Does changing the function definition to something like this do what you are expecting?
def token_pipeline(parameters: FlowParameters = FlowParameters())

Giuliano Mega

11/10/2022, 2:41 PM
Oh I see. I didn't think of it because: 1. it's usually not a good idea to have mutable objects in function's defaults; 2. pydantic has its way of specifying defaults, which is by setting them in the model. Is there any reason not to have the flow decorator do this job of attempting to instantiate the parameter with no args and pass it along if not supplied? That's what I actually thought it would do.
And thanks a lot for the help! 🙂