https://prefect.io logo
n

Nicholas Thompson

07/18/2023, 11:29 PM
Hi all, would someone be able to help check my understanding on how optional parameters work in the latest prefect versions?? I've been using pydantic models to partition my flow inputs, and noticed that when migrating from 2.10.18 to 2.10.21, that if I have a required field inside an optional input model, I can't run the deployment from the UI when the model is set to None. I just want to check if that's intentional, or something that's going to be fixed eventually??
👀 1
I've got an example to show what I mean - say we have a flow set up similar to the following, where I've defined an
InputModel
, which has one required parameter. This input model is then used as an optional parameter in my flow. Up to and including prefect version 2.10.18, I've been able to run a flow with the
optional_input_model
parameter set to none, which by extension means the
required_field
on the input model is also left unspecified.
Copy code
from typing import Optional

import prefect
from pydantic import BaseModel


class InputModel(BaseModel):
    required_field: int


@prefect.flow(name="test-flow")
def flow(
    required_integer: int,
    optional_input_model: Optional[InputModel] = None,
) -> None:
    logger = prefect.get_run_logger()

    <http://logger.info|logger.info>(f"{required_integer=}")
    <http://logger.info|logger.info>(f"{optional_input_model=}")
After trying to upgrade to the latest version, 2.10.21, I'm finding that I can't run the flow from the UI, because prefect complains that the
required_field
in the input model is required (see my screenshot). Previously this wasn't the case, the flow would have
optional_input_model
set to None, and you'd still be able to run the deployment from the UI. Interestingly, when I try run the flow from a python terminal with the input model left as None, things work fine. It also works fine when I switch to the json view in run tab, so I think this is an issue on the UI end
c

Christopher Boyd

07/19/2023, 12:46 AM
Hi Nicholas, I’ll test this and raise it with the team to see if this is expected - I’m not sure that it is , but want to validate
n

Nicholas Thompson

07/19/2023, 1:07 AM
Cheers mate!
Hey @Christopher Boyd, just checking to see if there was any progress made here?
c

Christopher Boyd

07/21/2023, 12:29 AM
Hey Nicholas , I opened this issue , looking to get an update from the backend team - https://github.com/PrefectHQ/prefect-ui-library/issues/1599
n

Nicholas Thompson

07/21/2023, 12:45 AM
Thanks mate appreciate it, I'll follow updates there