Hey all, I’m noticing a bug in Prefect UI wrt **k...
# ask-community
a
Hey all, I’m noticing a bug in Prefect UI wrt **kwargs. I’ve set
batch_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.
c
I think this might be a bug. But it might depend on which version of pydantic you’re using. Can you let me know if you’re using v1 or v2?
I’ll try and reproduce
a
We actually don’t use pydantic. It’s just type hints for our own understanding and debugging purposes.
thank you 1
c
@Avinash Santhanagopalan I was able to reproduce the
null
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.
thank you 1
a
Would 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
Copy code
@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 to
None
(like
Optional[str] = None
then it will not be required
That is what I suspected. We are doing
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
Copy code
>>> k = None
>>> k.setdefault("some", "value")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'setdefault'