https://prefect.io logo
#prefect-community
Title
# prefect-community
j

Jai P

05/27/2022, 3:59 PM
👋 hullo! curious, in prefect 2 is there a way to set some flow-level context that are accessible by all sub-flows/tasks?
basically something like:
Copy code
@flow
def my_flow():
    context["my_cool_variable"] = "blah"
    my_subflow()


@flow
def my_subflow():
    print(context["my_cool_variable"])
    my_task()


@task
def my_task():
    print(context["my_cool_variable"])
should have the output
Copy code
[my_subflow] blah
[my_task]    blah
k

Kevin Kho

05/27/2022, 4:03 PM
What happens if you define it outside tasks and flows? I think it might work
j

Jai P

05/27/2022, 4:06 PM
I would guess that does, but what if everything isn't colocated? i guess some funny things can happen there
another piece is...execution isn't guaranteed on the same instance right? so that adds some complexity
k

Kevin Kho

05/27/2022, 4:13 PM
Well yes it might run into problems if things aren’t colocated but I think in general this global variable might be bad practice
j

Jai P

05/27/2022, 4:18 PM
yeah 😞
we definitely can get around it by just passing things around in the arguments for tasks, but was curious
5 Views