I have a quick question: how can I set a flow_run_...
# prefect-community
m
I have a quick question: how can I set a flow_run_id within the call of a
FLOW_OBJ.run()
? I'm currently doing the following:
Copy code
with prefect.context(flow_run_id="asdf"):
            EMAIL.run(flow_run_id="asdfasdf", name="TEST")
neither (context, nor the variable in the kwargs of the
run
function) actually change the flow_run_id when its output in the logger 😞 Do I need to wrap the flow_run_id in a state variable? If so whats the best way to do this? Finally, I'm running this flow over a dask cluster so idk if my issue here is affected by this issue: https://github.com/PrefectHQ/prefect/issues/2883
n
Hi @Michael Reeves - are you trying to do this purely with Core? If so, this isn't currently possible without overwriting the
flow.run
method since it's currently being reset there. This is something we can expose though to make it a mutable prop when running locally.
m
that would be wonderful 🙂
idk if that would cause a horrible change in the codebase? I figured as much from this line: https://github.com/PrefectHQ/prefect/blob/a88c86174b70b9de6c110f1c1524b70d4b18b96e/src/prefect/core/flow.py#L1005
Is there anything I can do in the meantime as a workaround? Or do I need to run my own fork and change
flow.run()
? Thanks for the help 🙂
c
we can make this PR quickly if you’re willing to work off the master branch
upvote 2
m
yeah I can do that
I think I already am? let me check
n
We'll have to open and merge a PR to allow that first @Michael Reeves
👍 1
m
anything I can do to help?
c
if you’d like to make the PR that’d be cool! You need to loop over each of these variables: https://github.com/PrefectHQ/prefect/blob/a88c86174b70b9de6c110f1c1524b70d4b18b96e/src/prefect/core/flow.py#L1002-L1007 and use
Copy code
flow_run_context.setdefault(key, value)
m
Ok wasn't running master branch, but now I am 😄 Yup EZ, is there a format I should follow for the PR?
c
once you make that change, run
black .
on the codebase to format it
that’s it!
m
idk if I have the
black
binary on my computer?
c
run
pip install black
and that’s all you need
👍 1
m
sorry that took a while haha, heres the PR: https://github.com/PrefectHQ/prefect/pull/3163
🚀 1
😄 1
🙂
c
Awesome thanks! I gave you a suggestion to simplify it
m
ok fixed it
how does that line work? I've never used the setdefault function before with a dictionary
c
So setdefault is essentially “if the key does not already exist in the dictionary, use this value, else just keep it as-is”
I need to step away from my computer for a bit but hopefully you’re already unblocked and we can merge this later this evening!
👍 1
m
sweet!
I really appreciate this 🙂
c
yea no problem!