Skip to content

[16.0][FIX] queue_job: rebind args/kwargs to inner cursor in in_temporary_env#926

Open
deeniiz wants to merge 2 commits intoOCA:16.0from
nuobit:16.0-fix-queue_job-rebind-args-in-temporary-env
Open

[16.0][FIX] queue_job: rebind args/kwargs to inner cursor in in_temporary_env#926
deeniiz wants to merge 2 commits intoOCA:16.0from
nuobit:16.0-fix-queue_job-rebind-args-in-temporary-env

Conversation

@deeniiz
Copy link
Copy Markdown

@deeniiz deeniiz commented Apr 29, 2026

Job.in_temporary_env() rebinds self.recordset to the inner cursor via the @env.setter, but leaves self.args and self.kwargs on the outer worker cursor where _prevent_commit is patched. A cr.commit() reached through any recordset argument then raises RuntimeError: Commit is forbidden in queue jobs even with allow_commit=True. Typical case: a connector exporter taking a binding and a related record, committing inside binder.bind_export(...).

Introduced by #910.

Fix: after the env swap, walk self.args and self.kwargs recursively (BaseModel, list, tuple, dict) and rebind each recordset with value.with_env(value.env(cr=new_env.cr)) — only the cursor changes, uid/su/context are kept. Originals restored in the finally, like self._env.

Regression test in test_queue_job passes the same recordset as positional arg, list element and dict value, checks cursor identity in all three, then commits. Run through RunJobController._runjob.

@deeniiz
Copy link
Copy Markdown
Author

deeniiz commented Apr 29, 2026

@eantones @guewen, can you please review it?

@OCA-git-bot
Copy link
Copy Markdown
Contributor

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

@OCA-git-bot OCA-git-bot added series:16.0 mod:queue_job Module queue_job mod:test_queue_job Module test_queue_job labels Apr 29, 2026
@deeniiz deeniiz force-pushed the 16.0-fix-queue_job-rebind-args-in-temporary-env branch from 820d983 to 1360a12 Compare April 29, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:queue_job Module queue_job mod:test_queue_job Module test_queue_job series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants