Is it possible to access the flow name from a task...
# prefect-community
a
Is it possible to access the flow name from a task run context? I can use
get_run_context().flow.name
from the flow context but am unable to find an equivalent on the task level
z
We’d recommend passing it through to the task explicitly for now; we’re hesitant to add things to the task run context since they often need to be serialized and run somewhere distributed.
If you’re running on a single process, you can use
FlowRunContext.get()
to retrieve the flow run context from a task, but if tasks are sent to run somewhere else (e.g. with Dask) it will be
None
a
got it, thanks!
a
Has there been any update here? It'd be convenient in a few places to be able to get the flow name from anywhere within that flow.
z
What’s your use case?
a
One example is: the flow name is a part of a key that we use to retrieve data created by flows, to correlate data provenance. but sometimes that data is created in a @task context instead of out in the @flow toplevel
z
Why doesn’t passing the flow name to tasks explicitly work?
a
we could go through our code and add an argument to every task that touches S3 and pass in the
prefect.context
object, but that seems suboptimal
z
Well I wouldn’t recommend passing the full context, just the name but yeah. The problem is that the task run context needs to be as lightweight as possible so it’s scalable. For the people that don’t need the flow run metadata and have thousands of task runs the memory overhead can be pretty significant.
a
We also like to hide thjese sorts of details from our scientists to the extent possible and not expose the guts of the wiring, so just knowing where the data should go or come from is a part of the value add
z
That makes sense.
a
just the name works in this case, but in others we might want some other piece of info as well - flow run id, deployment id(?), etc
z
Well, the flow run id is attached to the task run that’s available in the context.
This is the problem though, people want a bunch of data there but then we see regressions for the users that don’t want it.
We’ll need to find a solution that works for everyone, we can’t just throw whatever is asked for onto the context.
a
ParentContextAwareTask
🤔
okay, i hear the answer tho, will go back to the drawing board and figure out the best solution given what we have today, thanks
z
😄 I definitely understand where you’re coming from
a
same 🙂