https://prefect.io logo
Title
m

Michael Reeves

08/14/2020, 8:24 PM
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:
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

nicholas

08/14/2020, 9:26 PM
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

Michael Reeves

08/14/2020, 9:28 PM
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

Chris White

08/14/2020, 9:30 PM
we can make this PR quickly if you’re willing to work off the master branch
:upvote: 2
m

Michael Reeves

08/14/2020, 9:31 PM
yeah I can do that
I think I already am? let me check
n

nicholas

08/14/2020, 9:31 PM
We'll have to open and merge a PR to allow that first @Michael Reeves
👍 1
m

Michael Reeves

08/14/2020, 9:32 PM
anything I can do to help?
c

Chris White

08/14/2020, 9:33 PM
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
flow_run_context.setdefault(key, value)
m

Michael Reeves

08/14/2020, 9:34 PM
Ok wasn't running master branch, but now I am 😄 Yup EZ, is there a format I should follow for the PR?
c

Chris White

08/14/2020, 9:35 PM
once you make that change, run
black .
on the codebase to format it
that’s it!
m

Michael Reeves

08/14/2020, 9:35 PM
idk if I have the
black
binary on my computer?
c

Chris White

08/14/2020, 9:35 PM
run
pip install black
and that’s all you need
👍 1
m

Michael Reeves

08/14/2020, 11:42 PM
sorry that took a while haha, heres the PR: https://github.com/PrefectHQ/prefect/pull/3163
🚀 1
😄 1
🙂
c

Chris White

08/14/2020, 11:58 PM
Awesome thanks! I gave you a suggestion to simplify it
m

Michael Reeves

08/15/2020, 12:13 AM
ok fixed it
how does that line work? I've never used the setdefault function before with a dictionary
c

Chris White

08/15/2020, 12:14 AM
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

Michael Reeves

08/15/2020, 12:22 AM
sweet!
I really appreciate this 🙂
c

Chris White

08/15/2020, 1:39 AM
yea no problem!