Hi *TL;DR: How to overwrite context in `config.to...
# ask-community
k
Hi TL;DR: How to overwrite context in
config.toml
by context provided in prefect UI's context section while running a flow? I am facing problem with updating/overwriting context values from prefect UI. I have defined a user configuration file for the agent at
Copy code
~/.prefect/config.toml
with following syntax
Copy code
[context]
postgresdb = "production"
Now, I want to update this attribute
postgredb
from the UI by passing context with same name and different value like following
Copy code
{
  "postgresdb": "test"
}
When I obtain this context name in task, it gives me the value from
config.toml
not the updated value from the context provided in the UI
Copy code
print(prefect.context.get('postgresdb'))
>>>production
Can someone guide me through this? Please. I have read the documentation multiple times and have also gone through the prefect source code in an attempt to understand how contexts get merged but I could not understand it. From the code, it appears that whatever context is passed through
**kwargs
overwrites the context in the
config.toml
. I believe prefect UI is passing context via
**kwargs
only.
j
Hi @Krishna Devenda i just ran a flow to see if I could reproduce this and I am unable to! My context sent from the UI updated appropriately 🤔 Could you open up this as an issue on the repo w/ an example of your flow so we can look at it there?
k
Yeah sure, I will open up an issue on the repo with steps to reproduce. I noticed a strange behaviour where if there are more than one task in the flow and at least one task is getting executed before a task in which I retrieve the context, the context does not get updated but if the task in which I retrieve the context gets executed first of all, the context gets updated.
Hi @josh, I have opened an issue on the repo. Here's the link to the issue https://github.com/PrefectHQ/prefect/issues/3956 Please have a look and thank you for your time.🙏
j
Thank you!