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] Add queue_job.keep_context ir.config_parameter #613

Closed
wants to merge 1 commit into from

Conversation

amh-mw
Copy link
Contributor

@amh-mw amh-mw commented Dec 21, 2023

When this parameter is set, queue_job always preserves 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.

Fixes #406.

@OCA-git-bot
Copy link
Contributor

Hi @guewen,
some modules you are maintaining are being modified, check this out!

@amh-mw
Copy link
Contributor Author

amh-mw commented Dec 21, 2023

Just for general amusement, abridged from code that I wrote to import over a decade of users and data from a legacy system:

self.with_context({
    'bus_no_notify': True, # custom
    'calendar_event_create_no_constrain': True, # custom
    'mail_auto_subscribe_no_notify': True, # odoo
    'mail_create_nolog': True, # odoo
    'mail_create_nosubscribe': True, # odoo
    'mail_notrack': True, # odoo
    'no_geo_complete': True, # custom
    'no_mail_to_attendees': True, # odoo
    'no_reset_password': True, # odoo
    'quickbooks_no_prepare': True, # custom
    'tracking_disable': True # odoo
}).with_delay(...)._cron_migrate()

It is really important that context is preserved or all kinds of side effects are triggered.

@amh-mw amh-mw force-pushed the 15-keep_context branch 2 times, most recently from 69e66b4 to 9d8d098 Compare December 21, 2023 22:06
When this parameter is set, queue_job always preserves 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.

Fixes OCA#406.
@amh-mw
Copy link
Contributor Author

amh-mw commented Dec 21, 2023

@acsonefho @florian-dacosta Any interest in reviewing this queue_job.keep_context pull request?

@sbidoul
Copy link
Member

sbidoul commented Dec 22, 2023

@amh-mw If my memory is correct, you should rather port https://github.com/OCA/queue/tree/14.0/queue_job_context from 14 to 15. In 16 it is not necessary anymore as it is the default.

@amh-mw
Copy link
Contributor Author

amh-mw commented Dec 22, 2023

It looks like queue_job_context uses a hardcoded list of context keys that I would have to inherit the class and override?

return ("tz", "lang", "allowed_company_ids", "force_company", "active_test")

I don't prefer that. I just want to flip a switch and get all the context.

Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Apr 21, 2024
@github-actions github-actions bot closed this May 26, 2024
@amh-mw amh-mw deleted the 15-keep_context branch May 27, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants