https://prefect.io logo
Title
g

Geert-Jan Van den Bogaerde

04/14/2022, 3:13 PM
Hi all, anyone know if there is a way to retrieve the run config parameters, specifically the labels, from within a flow programmatically at flow runtime? Haven't been able to find it in the docs.
k

Kevin Kho

04/14/2022, 3:18 PM
There is no easy way exposed so youโ€™d need to use the GraphQL API. Let me see if I can find an example
g

Geert-Jan Van den Bogaerde

04/14/2022, 3:27 PM
Thanks for the quick reply, Kevin! Actually, this seems to work after a little more digging:
@task
def get_current_flow_run_labels():
logger = prefect.context.get('logger')
flow_run_id = prefect.context.get("flow_run_id")
flow_run_view = FlowRunView.from_flow_run_id(flow_run_id)
labels = flow_run_view.labels
<http://logger.info|logger.info>(f"Labels: {labels}")
return labels
k

Kevin Kho

04/14/2022, 3:28 PM
Oh nice. Glad you figured it out
๐Ÿ‘ 1
g

Geert-Jan Van den Bogaerde

04/14/2022, 3:35 PM
Funny story: it was actually Github Copilot (https://copilot.github.com) that got me on the right track, it didn't get it 100% correct but suggested FlowRunView which got me there ๐Ÿ™‚
k

Kevin Kho

04/14/2022, 3:36 PM
No way! Thatโ€™s wild. Has it been accurate for you when working with Prefect?
g

Geert-Jan Van den Bogaerde

04/14/2022, 3:53 PM
More and more so. Part of that is that it clearly learns from your own codebase as well as the larger training set, and it must prioritize those somehow: it will almost always recognize patterns that I repeat a lot in my own codebase. For instance i very often use task_args = dict(name = "some friendly name"), and it will usually suggest that automatically when i call a task. Another example: we almost always do a transform task on 3 different types of dataframes in turn as 3 task calls, when I code the first two in a new flow it will without fail complete the third one for me But other times it's suggesting things that must come from other codebases, as I've just checked and we've never used FlowRunView before in our repo :-)
Besides the prefect specific stuff, for pandas it clearly has a lot of training data, as there it's usually enough to just give it a comment describing what you want your function to do and it will pretty much write the whole thing, if it's anything remotely common
k

Kevin Kho

04/14/2022, 3:59 PM
Wow
a

Anna Geller

04/14/2022, 4:13 PM
thanks for sharing, very cool!
can you remove the tag of Aui Task though? this poor person was tagged so many times accidentally because of
@task
๐Ÿ˜‚
๐Ÿ˜‚ 2
g

Geert-Jan Van den Bogaerde

04/14/2022, 6:08 PM
Thanks, Anna! Removed the tag. Hopefully with Prefect 2.0 / Orion nobody has a name that matches
@flow
;-)
a

Anna Geller

04/14/2022, 6:10 PM
Thank you! Yes, fingers crossed! ๐Ÿ˜„๐Ÿคž