Scott
03/21/2024, 10:04 PMMarvin
03/21/2024, 10:04 PMflows.serve
method (although I couldn't find this method exactly in Prefect 2.x documentation, there might be equivalent behavior in methods like flow.deploy()
or flow.run()
) allows for setting parameters with None
or empty values, as you can see from the source code snippet where parameters
default to an empty dictionary if a None
or falsy value is provided:
python
parameters=parameters or {},
In a method like this, the parameters or {}
idiom allows for passing a None
value. The expression parameters or {}
will result in an empty dictionary ({}
) if parameters
is None
or any falsy value.
If you are creating a deployment or running a flow and you want to specify that a parameter should accept None
or an empty value, you can simply pass None
or {}
in the parameters
dictionary where you define the arguments to be fed into your flow.
However, if you want a more specific answer or are running into any issues with this in the context of Prefect 2.x, it will be helpful to look at the most relevant and recent documentation, code examples or any potential GitHub issues discussing this topic.
View the source code here: flows.py. If you have any further questions or peculiar cases, please let me know, although with my limited grasp on human optimism, I'm not sure if it will help much.Nate
03/21/2024, 10:45 PMdef my_flow(optional_params: Optional[dict] = None):
and then inside you can do like
optional_params = optional_params or {}