When creating a deployment that sets the value of ...
# ask-community
d
When creating a deployment that sets the value of some parameter's of a flow, is it possible to prevent the parameters options from being changed in the UI? For example if I have the below. The value is defaulted but still editable in the UI (attached). Is it possible to prevent this or hide the first parameter all together?
Copy code
class testEnum1(Enum):
    a = "a"
    b = "b"


class testEnum2(Enum):
    c = "c"
    d = "d"


@task(log_prints=True)
def task1(enum1, enum2):
    print(f"enum1: {enum1}")
    print(f"enum2: {enum2}")


@flow
def test_flow(
    param1: testEnum1,
    param2: testEnum2,
):
    task1(enum1=param1, enum2=param2)


if __name__ == "__main__":
    deployment = test_flow.deploy(parameters={"param1": "a"})
c
Hi Daniel! This is not currently possible; may I ask how you would use this instead of removing
param1
as a parameter to your flow?
d
Hi Chris, I am generating flows, tasks, and their parameter validation classes dynamically with config data called from an API. This works okay but requires some spaghetti to get prefect to find the flow such as editing the generated functions name
undecorated_flow_function.__name__ = flow_name
and manually adding the decorated flow to globals
globals()[flow_name] = decorated_flow
. It would be preferred to generate these flows as deployments of a single flow instead of different flows.
param1
is something that needs to vary between the flow versions at deployment time but should always be the same when the flow is run. For example, let's say I need to deploy 1 flow per customer,
param1
could be something like the customer's name.
c
I see I see; so I played around with making the type hint itself dynamic but that's tricky and could lead to unexpected behavior. Would you mind opening an issue for this on our repo? Ultimately I think something like the following will be relatively straightforward to implement (there might be a better name than
freeze
too):
Copy code
from prefect import freeze

deployment = test_flow.deploy(parameters={"param1": freeze("a")})
Basically all we have to do is manipulate the underlying OpenAPI schema (which is what the API uses to expose choices / types) so that "param1" is stored as an Enum with only one possible value ("a"). All of this logic can live on the client too which is nice.
d
For sure, right here: https://github.com/PrefectHQ/prefect/issues/11073 Thanks for the help. I was considering going down the dark path of generating my Prefect flows with jinja to achieve similar functionality so this would be a much appreciated improvement.
c
nice thank you!