Avinash Santhanagopalan
04/18/2024, 6:34 PMbatch_kwargs: Optiona[Dict[str, Any]]
in the flow and we deployments on that flow. But somehow its showing up as null
in the Custom Run UI and it causes an error when I submit saying None is not of type object
. It only works if I give {}
. Is this expected? Its quite hard to hard code this every time we use the custom run.Craig Harshbarger
04/18/2024, 10:25 PMCraig Harshbarger
04/18/2024, 10:25 PMAvinash Santhanagopalan
04/18/2024, 11:21 PMCraig Harshbarger
04/19/2024, 2:33 PMnull
piece and have a fix for that here.
But I wasn't quite able to reproduce what you have in your screenshot. Would you mind sending me a complete minimum reproduction and also letting me know what version of python you are on?
Also one thought I had is that Optional
will produce a json schema (what we're using to create these forms) where the value can also be None
(or null
in json). But it doesn't actually make it so you can omit the value. Optional[str]
for example still produces a required field, it will just allow you to enter str
or None
. However if you set the default value of the parameter to None
(like Optional[str] = None
then it will not be required and the UI will reflect that.Avinash Santhanagopalan
04/19/2024, 3:09 PMWould you mind sending me a complete minimum reproduction and also letting me know what version of python you are on?We are on python 3.10 and prefect version 2.14.17. I think something like this might cause this but not 100% sure
@flow
def test_flow(**kwargs: Optiona[Dict[str, Any]]) -> None:
print(kwargs)
if __name__ == "__main__":
Deployment.build_from_flow(
flow=test_flow,
work_pool_name="default",
work_queue_name="default",
)
However if you set the default value of the parameter toThat is what I suspected. We are doing(likeNone
then it will not be requiredOptional[str] = None
batch_kwargs.setdefault("some_arg", "test")
in all the tasks inside the flow so we actually can’t set it to None
else we will run into an error like this
>>> k = None
>>> k.setdefault("some", "value")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'setdefault'