Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] queue: Store context in order to reuse it #121

Closed
wants to merge 1 commit into from

Conversation

etobella
Copy link
Member

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.

@guewen
Copy link
Member

guewen commented Jan 31, 2019

IMO it is better to add an explicit argument in the method if you want to keep something.

@etobella
Copy link
Member Author

That is what I have usually done and I always thought that it was a limitation.
Maybe there is a reason for this behaviour and it is a wrong approach to use this PR.

@pedrobaeza pedrobaeza added this to the 11.0 milestone Mar 7, 2019
@pedrobaeza
Copy link
Member

I also agree that is good to add corresponding arguments, but there can be context values that are out of your control, like force_company, tz or lang (that doesn't correspond with the job owner lang). Is that the case, @etobella ?

@guewen
Copy link
Member

guewen commented Mar 7, 2019

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 force_company, tz, lang, then I would agree that we should keep a stripped-down copy of the context keeping only a list of safe fields.

@etobella
Copy link
Member Author

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
Copy link
Member Author

etobella commented Mar 7, 2019

@guewen The list of safe context keys has been added. It might be better now.

queue_job/job.py Outdated Show resolved Hide resolved
@@ -27,6 +27,20 @@ def _register_hook(self):
for job_method in job_methods:
self.env['queue.job.function']._register_job(self, job_method)

@api.model
def get_job_context_keys(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these methods should be private IMO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if the safe list really needs to be global, then it can be added to queue.job

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea about the job. I will make the change

@sbidoul
Copy link
Member

sbidoul commented Mar 8, 2019

Will this pass some context to the job by default, that was not passed before?

@etobella
Copy link
Member Author

etobella commented Mar 8, 2019

Yes, the context was not passed to the job.

@sbidoul
Copy link
Member

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
Copy link
Member Author

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

@jarroyomorales
Copy link

@etobella Travis already fixed in #172

@etobella etobella force-pushed the 11.0-add-context branch 2 times, most recently from 852cbe6 to d9716c6 Compare October 1, 2019 03:11
@etobella
Copy link
Member Author

etobella commented Oct 1, 2019

@simahawk your comments have been attended

@guewen guewen mentioned this pull request Oct 29, 2020
@lmignon
Copy link
Contributor

lmignon commented Oct 30, 2020

With this implementation, how can we add a new key into the allow_contextlist? #273 (comment) could be the right way to provide this kind of info.

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@maljac
Copy link
Member

maljac commented Jul 13, 2021

Any chance this PR will be merged soon (and maybe ported to v10)?

maljac added a commit to maljac/queue that referenced this pull request Jul 13, 2021
@guewen
Copy link
Member

guewen commented Jul 13, 2021

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
Copy link
Member

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

@etobella etobella closed this Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants