Mansour Zayer
03/22/2023, 4:36 PM**kwargs
for its input parameter like my_flow (p_1, p_2, **kwargs:dict[str, bool])
. When I run the flow from the UI, I get
Validation of flow parameters failed with error:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/prefect/engine.py", line 296, in retrieve_flow_then_begin_flow_run
parameters = flow.validate_parameters(flow_run.parameters)
File "/usr/local/lib/python3.9/site-packages/prefect/flows.py", line 339, in validate_parameters
raise ParameterTypeError.from_validation_error(exc) from None
prefect.exceptions.ParameterTypeError: Flow run received invalid parameters:
- kwargs: value is not a valid dict
the parameter value is:
{
"kwargs": {
"p_1": false
}
}
Am I doing something wrong, or is this a bug in validate_parameters?
Thank youNate
03/22/2023, 7:41 PMMansour Zayer
03/22/2023, 7:53 PM@flow
async def my_subflow(
input_1: str,
skip_step_1: bool = False,
skip_step_2: bool = False,
skip_step_3: bool = False,
**kwargs: dict,
):
doing_something
@flow
async def parallel_orchestrator(skip_step: bool = False, list_of_input=["a", "b", "c", "d"], **kwargs:dict[str, bool]):
some steps here
await asyncio.gather(
*[
run_deployment(
name=f"my-subflow/...",
parameters=dict(input_1=input, **kwargs),
)
for input in list_of_input
]
)
Nate
03/22/2023, 8:07 PMdict[str, bool]
also just as a side note, I would generally recommend avoiding mutable defaults (like list_of_input
) for your flow parameters (this is an aggressively worded article š
but gets the point across)Mansour Zayer
03/22/2023, 8:16 PMdict
, dict[str, bool]
, Optional[dict]
), nothing worked.Nate
03/22/2023, 8:32 PM**kwargs
here, it feels like it may be simpler and more explicit if you replace it with something like static_kwargs: Dict[str, Any]
(not using **
) and just pass each instance of my_subflow
that dictionary - or is there a reason you can't do that?Mansour Zayer
03/22/2023, 8:51 PMNate
03/22/2023, 8:53 PMZanie
03/22/2023, 9:24 PMkwargs
you are actually specifying the type for each keyword argument**kwargs: dict
means that you accept any number of keyword arguments that are each a dictionary e.g. x={}, y={}
**kwargs: str
means that you accept strings e.g. x="", y=""
Mansour Zayer
03/23/2023, 4:47 PM**kwargs
like a regular parameter. For example, it's treated as mandatory, but you can't define default values for **kwargs
. Also, any type hint you use, the UI will try to cast the kwargs
value to that type. Therefore, I think this article doesn't apply 100% here.