Is there an easy way to access the flow’s name (no...
# prefect-community
Is there an easy way to access the flow’s name (not the flow run name) from a task running inside the flow in Prefect 2?
hi @Ilya Galperin do you mean the name of the function that's decorated with @flow? or the name of a deployment from which the flow run was created?
Heya Nate - not the name of the function itself but specifically the name of the flow defined in the decorator i.e.
we would want to find the value
you could do something like
Copy code
from prefect import flow, get_run_logger, task

def log_flow_name():
    logger = get_run_logger()
    <|>(f"I'm task that makes up a flow `{test.__name__}` with name: {}")

def test():

if __name__ == "__main__":
Copy code
❯ python
14:35:56.653 | INFO    | prefect.engine - Created flow run 'tourmaline-shark' for flow 'example_flow'
14:35:57.304 | INFO    | Flow run 'tourmaline-shark' - Created task run 'log_flow_name-96b8f2ed-0' for task 'log_flow_name'
14:35:57.306 | INFO    | Flow run 'tourmaline-shark' - Executing 'log_flow_name-96b8f2ed-0' immediately...
14:35:57.469 | INFO    | Task run 'log_flow_name-96b8f2ed-0' - I'm task that makes up a flow test with name: example_flow
14:35:57.556 | INFO    | Task run 'log_flow_name-96b8f2ed-0' - Finished in state Completed()
14:35:57.651 | INFO    | Flow run 'tourmaline-shark' - Finished in state Completed('All states completed.')
Thanks Nate. This is definitely a workable solution but since our tasks live in a different script than our flow function, I was wondering if there was a way to access the flow name directly from the flow context? Otherwise, we have to pass the flow function’s name attribute as a parameter into the task (which admittedly isn’t a huge lift if not).
from what I could see, the flow's name attribute doesn't live in the task run context, but yes you could totally pass it in to the tasks that need it as a parameter
Gotcha, thanks for confirming!