-
-
Notifications
You must be signed in to change notification settings - Fork 513
[18.0][IMP] queue_job: Improve context management. #768
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
base: 18.0
Are you sure you want to change the base?
Conversation
Hi @guewen, |
Maybe it would be better as a parameter to the |
@hildickethan I like this idea in principle, but haven't had enough coffee this morning to see how to pass |
What about things that can't be serialized? That would at least be the asterisk on "entire". I feel like the moment you call with_delay you generally know what context keys you could be interested in (or intentionally want to ignore!). Preserving the entire* context is all or nothing. |
Absolutely. That has been raised before in #432. Personally, I have never encountered a non-serializable context across the few dozen Odoo and OCA modules that I use, so... I didn't code around it.
This approach isn't a great fit for me personally, as I have a large number of context variables that I set at the top of large import jobs (per #613 (comment)), and my actual That said, # addition
self.env[model].with_context(a=1, b=2).with_delay(keep_full_context=True).func()
# replacement
self.env[model].with_context({'c': 3, 'd': 4}).with_delay(keep_full_context=True).func() Then the |
Great suggestion. Give me a bit and let me see what I can work up. |
Hmm looking at the "how" I think
a new field that gets passed through is overkill, Currently:
So this sets the context dictionary for the job from the current context, but only the key that are in the allow list.
then you could just
or for the full context
(or set it on |
Sorry somehow I posted my comment while editing. Please see updated version, I don't think "preserve entire context" needs its own setting - just pass some or copy all. |
maybe better
so you can explicitly set it to something falsy to disable it if it might have been set before (otherwise you would have to make it an empty dictionary, this way None works just as well) |
It's a requirement for me. I have far too many context variables to copy paste them across |
Gotcha. If there's a performance issue an assignment would be better than a .copy().
Like this?
This way would still require inserting something like |
Sorry maybe I misunderstood. You won't have to copy individual context variables if you set |
9496787
to
dac76d1
Compare
dac76d1
to
b56174b
Compare
When the `queue_job_keep_context` context variable is set, always preserve the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. When the `queue_job_context_keys` context variable is set, preserve the given keys in addition to those normally specified by `_job_prepare_context_before_enqueue_keys`.
b56174b
to
46d62d1
Compare
oh good - I wasn't sure if that was possible. |
I chose to remain out of the context modification game, so adding and using a new context value looks like self.with_context(a=1, queue_job_context_keys=['a']).with_delay().func() I dislike the repetition, but I think it's preferable to reimplementing |
I think that's good to differentiate and be explicit. The context is often set somewhere else. |
Fixes #406. Formerly #613.