Skip to content

[16.0][FIX] queue_job: rebind args/kwargs to inner cursor in in_temporary_env (backup) - #2

Closed
eantones wants to merge 2 commits into
16.0from
16.0-fix-queue_job-rebind-args-in-temporary-env-eager
Closed

[16.0][FIX] queue_job: rebind args/kwargs to inner cursor in in_temporary_env (backup)#2
eantones wants to merge 2 commits into
16.0from
16.0-fix-queue_job-rebind-args-in-temporary-env-eager

Conversation

@eantones

@eantones eantones commented Aug 19, 2026

Copy link
Copy Markdown
Member

Backup of the eager implementation before updating the upstream PR to the lazy one. Not meant to merge.

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 OCA#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.

@eantones eantones closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants