Uh oh!
There was an error while loading. Please reload this page.
[IMP] queue: Store context in order to reuse it - #121
Conversation
guewen
commented
Jan 31, 2019
IMO it is better to add an explicit argument in the method if you want to keep something. |
etobella
commented
Jan 31, 2019
That is what I have usually done and I always thought that it was a limitation. |
pedrobaeza
commented
Mar 7, 2019
I also agree that is good to add corresponding arguments, but there can be context values that are out of your control, like |
I find that the context is sometimes/often out of control, it may even contain values which cannot be serialized. If the requirement concerns predefined fields, such as |
etobella
commented
Mar 7, 2019
It is true, that reusing context might be crazy, but it is a tool that is used sometimes and it is interesting to store it somehow. A list of context could be fine. I will work on a safe list of fields. |
etobella
commented
Mar 7, 2019
@guewen The list of safe context keys has been added. It might be better now. |
Uh oh!
There was an error while loading. Please reload this page.
| self.env['queue.job.function']._register_job(self, job_method) | ||
| @api.model | ||
| def get_job_context_keys(self): |
There was a problem hiding this comment.
these methods should be private IMO
There was a problem hiding this comment.
Suggestion: setup the context keys to pass on the @job decorator
@job(context_allow=['foo'])
With ['force_company', 'lang', 'tz'] by default and new keys added to the list.
The filtering of the context keys could then be hidden in the job implementation details, instead of cluttering the base model (I try hard to put as less method as possible here).
Would it work for you?
There was a problem hiding this comment.
Or if the safe list really needs to be global, then it can be added to queue.job
There was a problem hiding this comment.
great idea about the job. I will make the change
sbidoul
commented
Mar 8, 2019
Will this pass some context to the job by default, that was not passed before? |
etobella
commented
Mar 8, 2019
Yes, the context was not passed to the job. |
sbidoul
commented
Mar 8, 2019
@etobella then I'd say it must not be passed at all unless asked explicitly by the developer, as this could change the behavior of existing deployments. |
etobella
commented
Mar 8, 2019
@sbidoul That is the last change we applied today. The context keys are defined on the job decorator in order to ensure flexibility |
f6994f6 to
d9b8bfaComparejarroyomorales
commented
Sep 30, 2019
852cbe6 to
d9716c6Compared9716c6 to
494782eCompareetobella
commented
Oct 1, 2019
@simahawk your comments have been attended |
lmignon
commented
Oct 30, 2020
With this implementation, how can we add a new key into the |
OCA-git-bot
commented
May 27, 2021
This PR has the |
maljac
commented
Jul 13, 2021
Any chance this PR will be merged soon (and maybe ported to v10)? |
There is an issue I'm not sure how to handle, which is that in higher versions of Odoo, the context should be stored in the Serialized records (see #281, #283). This change cannot be ported as-is to Odoo 12+. My feeling is that we should address this problem in more recent versions of Odoo, and see how to transition on migrations. Otherwise we will support something in 11.0 that will be lost when you upgrade... |
guewen
commented
Jul 13, 2021
FWIW in many cases (actually I never needed the context for this reason), it is IMO better to pass an explicit argument to the job method than rely on an arbitrary context |
With these PR, the context is stored and it can be used in the job.
Sometimes, you don't want to lose the context of the user.