How do I get the flow name at runtime I was trying...
# prefect-server
g
How do I get the flow name at runtime I was trying prefect.context.get(‘flow_name’)
k
Hi @Garret Cook, did you try
prefect.context.flow_name
?
g
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
Oh ok I’ll try this
z
Are you looking for the
flow_run_name
or the
flow_name
?
👍 1
g
oh, I’d the flow_run_name I think, the dynamically generated one, like ‘exhausted-mongoose’
z
It should be available under that key then 🙂
g
prefect.context.flow_run_name. << that one?
z
Yep!
g
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
When are you calling this?
If the flow run isn't running at the time, it won't exist yet
g
I thought perhaps, but why doesn’t the call get deferred then? Do I need to template that string differently?
z
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
ah, I bet that is the issue
g
Lemme try that