https://prefect.io logo
Title
k

kevin

08/14/2020, 10:17 PM
Hey guys, is it "prefect legal" to inject context into
prefect.context
at runtime? More concretely, can I do something like this:
with Flow('test') as flow:
    do_stuff()

with prefect.context(foo='bar'):
    flow.run()
and if not what would be the correct way to inject context after defining a flow?
n

nicholas

08/14/2020, 10:21 PM
Hi @kevin - that's perfectly valid! The docs have some advanced use cases of that exactly.
k

kevin

08/14/2020, 10:23 PM
oh that's great, as a corollary if I'm assuming it would be valid to do something like this:
with Flow('test') as flow:
    do_stuff()
def stuff_wrapper(foobar):
    with prefect.context(foo=foobar):
        flow.run()
and call
stuff_wrapper
but I want to make sure.
n

nicholas

08/14/2020, 10:24 PM
I imagine that would work just fine 👍
k

kevin

08/14/2020, 10:24 PM
thanks! appreciate the quick response