Skip to content

[12.0][FIX] queue_job: don't enqueue dependent jobs after a retryable postpone (closed cursor)#944

Merged
guewen merged 1 commit into
OCA:12.0from
ForgeFlow:12.0-fix-queue_job-closed-cursor-retryable
Jul 21, 2026
Merged

[12.0][FIX] queue_job: don't enqueue dependent jobs after a retryable postpone (closed cursor)#944
guewen merged 1 commit into
OCA:12.0from
ForgeFlow:12.0-fix-queue_job-closed-cursor-retryable

Conversation

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

Problem

Graph jobs that hit a Postgres serialization/concurrency error crash the /queue_job/runjob request with:

psycopg2.OperationalError: Unable to use a closed cursor.

Traceback tail:

controllers/main.py, in _enqueue_dependent_jobs -> job.enqueue_waiting()
job.py, in enqueue_waiting -> self.env.cr.execute(...)
OperationalError: Unable to use a closed cursor.

Root cause

In RunJobController.runjob, the except RetryableJobError handler calls the local retry_postpone(), which does:

job.env.clear()
with odoo.registry(job.env.cr.dbname).cursor() as new_cr:
    job.env = job.env(cr=new_cr)
    ...
    new_cr.commit()
# new_cr is closed here, but job.env.cr still points at it

The handler ended with env.cr.rollback() but no return, so control fell through to self._enqueue_dependent_jobs(env, job) ->
job.enqueue_waiting(), which runs self.env.cr.execute(...) on the closed cursor. This only triggers for jobs in a dependency graph that hit a retryable error, which is why it's intermittent.

Fix

Return right after the rollback in the RetryableJobError branch. A postponed job isn't done, so it must not release its dependents — and this avoids using the closed cursor. This matches upstream OCA queue_job behaviour in 14.0/15.0/16.0.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor Author

@guewen could you merge?

@guewen

guewen commented Jul 20, 2026

Copy link
Copy Markdown
Member

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 12.0-ocabot-merge-pr-944-by-guewen-bump-patch, awaiting test results.

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor Author

@guewen it seems you have to force merge it, as the automatic merge don't work in this case.

@guewen

guewen commented Jul 21, 2026

Copy link
Copy Markdown
Member

@guewen it seems you have to force merge it, as the automatic merge don't work in this case.

@MiquelRForgeFlow ok, I have no computer at hand, could you increase the patch version so I force merge?

…pone

When a job's perform() raised a PG serialization error, the runjob controller wrapped it as RetryableJobError and called retry_postpone(), which reassigns job.env to a temporary cursor inside a `with` block and closes it on exit. The handler then fell through to _enqueue_dependent_jobs() -> Job.enqueue_waiting(), running self.env.cr.execute() on that now-closed cursor and raising
"psycopg2.OperationalError: Unable to use a closed cursor".

A postponed job is not done and must not release its dependent jobs, so return right after the rollback. This also avoids touching the closed cursor. Aligns 12.0 with the upstream 14.0+ behaviour.
@MiquelRForgeFlow
MiquelRForgeFlow force-pushed the 12.0-fix-queue_job-closed-cursor-retryable branch from 3042c60 to 6d7d228 Compare July 21, 2026 11:41
@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor Author

could you increase the patch version so I force merge?

Done.

@guewen
guewen merged commit 23842b3 into OCA:12.0 Jul 21, 2026
2 of 5 checks passed
@guewen

guewen commented Jul 21, 2026

Copy link
Copy Markdown
Member

Thanks!

@MiquelRForgeFlow
MiquelRForgeFlow deleted the 12.0-fix-queue_job-closed-cursor-retryable branch July 21, 2026 11:51
@OCA-git-bot

Copy link
Copy Markdown
Contributor

@guewen your merge command was aborted due to failed check(s), which you can inspect on this commit of 12.0-ocabot-merge-pr-944-by-guewen-bump-patch.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

1 similar comment
@OCA-git-bot

Copy link
Copy Markdown
Contributor

@guewen your merge command was aborted due to failed check(s), which you can inspect on this commit of 12.0-ocabot-merge-pr-944-by-guewen-bump-patch.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

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.

4 participants