https://prefect.io logo
Title
g

Garret Cook

06/10/2021, 7:47 PM
How do I get the flow name at runtime I was trying prefect.context.get(‘flow_name’)
k

Kevin Kho

06/10/2021, 7:48 PM
Hi @Garret Cook, did you try
prefect.context.flow_name
?
g

Garret Cook

06/10/2021, 7:49 PM
well, that seems obvious, lemme try that
Traceback (most recent call last): File “client_backup_enrollment.py”, line 160, in <module> key=“{flow_run_name}/report.html”.format(flow_run_name=prefect.context.flow_name), AttributeError: ‘Context’ object has no attribute ’flow_name
k

Kevin Kho

06/10/2021, 7:50 PM
Oh ok I’ll try this
z

Zanie

06/10/2021, 7:53 PM
Are you looking for the
flow_run_name
or the
flow_name
?
👍 1
g

Garret Cook

06/10/2021, 7:54 PM
oh, I’d the flow_run_name I think, the dynamically generated one, like ‘exhausted-mongoose’
z

Zanie

06/10/2021, 7:54 PM
It should be available under that key then 🙂
g

Garret Cook

06/10/2021, 7:54 PM
prefect.context.flow_run_name. << that one?
z

Zanie

06/10/2021, 7:55 PM
Yep!
g

Garret Cook

06/10/2021, 7:56 PM
key=“{flow_run_name}/report.html”.format(flow_run_name=prefect.context.flow_run_name) yields: [root@prefect production-flows]# python3.6 client_backup_enrollment.py Traceback (most recent call last): File “client_backup_enrollment.py”, line 160, in <module> key=“{flow_run_name}/report.html”.format(flow_run_name=prefect.context.flow_run_name), AttributeError: ‘Context’ object has no attribute ‘flow_run_name’
z

Zanie

06/10/2021, 7:56 PM
When are you calling this?
If the flow run isn't running at the time, it won't exist yet
g

Garret Cook

06/10/2021, 7:57 PM
I thought perhaps, but why doesn’t the call get deferred then? Do I need to template that string differently?
z

Zanie

06/10/2021, 7:58 PM
If you call it from within a task it'll be deferred but if you call it elsewhere it may not
Can you share a little more context of where you're setting this?
g

Garret Cook

06/10/2021, 7:58 PM
ah, I bet that is the issue
g

Garret Cook

06/10/2021, 7:59 PM
Lemme try that