Hello, we are in the process of porting our Prefec...
# ask-community
l
Hello, we are in the process of porting our Prefect 1 flows to 2. There are several places that we used to get the flow name from context. Based on some articles like this. It seems like it may still be possible. However, when I call the suggested methods, I don't see flow name available. Looking at the porting guide I don't see that flow name is available in the "Example Output". Also a community member seems to be having the same problem in the comments below. Is there any way to get the flow name contextually during a run in Prefect 2? I'm running my flows locally in a docker container that matches our production environment with a fresh pull of
prefecthq/prefect:2-latest
Thanks!
z
prefect.context.get_run_context().flow_run.name
should do it — we don’t expose great ways to customize the name itself though yet!
l
Huh, that seems like what I need. When I execute my flow, I get an error like:
Copy code
AttributeError: 'TaskRunContext' object has no attribute 'flow_run'
z
Ah so the task run context doesn’t contain flow run information at this time
I’d call it in a flow and pass the value down to the task if relevant
l
Ahh ok. I'll give that a shot.
Ok, that gets me the dynamic animal-themed name, but not the name that we gave the flow.
I suppose I can just hard code it and pass it down from the flow.
z
The flow is different than the flow run in this case
I believe the flow is in the context too though
get_run_context().flow.name
🙌 1
l
Ohh, that gets it! Thanks.
I appreciate the help.