Hi all, anyone know if there is a way to retrieve ...
# prefect-community
g
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
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
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
Oh nice. Glad you figured it out
๐Ÿ‘ 1
g
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
No way! Thatโ€™s wild. Has it been accurate for you when working with Prefect?
g
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
Wow
a
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
Thanks, Anna! Removed the tag. Hopefully with Prefect 2.0 / Orion nobody has a name that matches
@flow
;-)
a
Thank you! Yes, fingers crossed! ๐Ÿ˜„๐Ÿคž