m

    Matt Wong-Kemp

    2 years ago
    Is there a way to set default context values for a flow? I'm wanting to put the endpoint to hit for API services into the context, and at the minute I'm entering this by hand every time I want to run from the UI. I guess ideally any prefect context values set when registering the flow would set them as defaults.
    j

    josh

    2 years ago
    Hey @Matt Wong-Kemp afaik there isn’t a way to set the default prefect context in terms of flow run-based context. 🤔 Quick thought, is there a reason why you aren’t using Parameters for this? They allow for defaults and can be passed / accessible to all tasks
    m

    Matt Wong-Kemp

    2 years ago
    think it was mainly because I felt dependency-injecting the API endpoint into all tasks was going to be a pain - in a sense that the endpoint you hit is part of the environment
    j

    josh

    2 years ago
    Ah I see, you could set default environment variables for your runs through the agent if you wanted to:
    prefect agent start --env PREFECT__CONTEXT__MY_API="https..."
    m

    Matt Wong-Kemp

    2 years ago
    Can I set a context value to the value of a task? If so I could define my flow:
    with Flow('foo') as flow:
        api = Parameter('endpoint')
        with prefect.context(endpoint=api):
    ok, makes sense - would be kind of nice if I could set defaults in the ui too?
    maybe doing it on the agent is the right thing here actually, thanks
    will it surface this value anywhere in the UI?
    j

    josh

    2 years ago
    It will not unfortunately 😕
    m

    Matt Wong-Kemp

    2 years ago
    that's fine, I can use it as a default and override on the ui
    @josh are these env vars on the agent config case-sensitive?
    ie if I do
    PREFECT___CONTEXT___FOO_BAR_BAZ
    is that
    FOO_BAR_BAZ
    or
    foo_bar_baz
    or either?
    j

    josh

    2 years ago
    Good question actually, I would have to check but I think they are case sensitive
    m

    Matt Wong-Kemp

    2 years ago
    while you're there - do they get carried across correctly in the Kubernetes agent? suspect not as they don't appear to be in my environment in the k8s job it spawns
    ah hang on, I might have misinterpreted this, I thought I'd be able to set the envar on the agent and it'd be carried over
    j

    josh

    2 years ago
    Ah wait that is actually a bug that has not been resolved! https://github.com/PrefectHQ/prefect/issues/2652
    m

    Matt Wong-Kemp

    2 years ago
    okay, I'll just pass by hand in the UI. +1 on that