Skip to content

Conversation

@sbidoul
Copy link
Member

@sbidoul sbidoul commented Jan 21, 2026

Commiting in a job would release the job lock, causing spurious restarts by the dead jobs requeuer.

Very much draft and untested at this point.

@OCA-git-bot
Copy link
Contributor

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

@guewen
Copy link
Member

guewen commented Jan 23, 2026

As I understand, it is very likely to happen when using queue_job_cron, as a lot of cron methods do intermediate commits

@sbidoul
Copy link
Member Author

sbidoul commented Jan 23, 2026

Precisely, yes.

@sbidoul
Copy link
Member Author

sbidoul commented Jan 23, 2026

@guewen an alternative would be to acquire the job lock with a separate cursor, the drawback being doubling the number of postgres connections required for jobs.

I'm not sure how prevalent the problem is, so to understand better I'm inclined to merge this so affected users get a clear error instead of hard to diagnose issues with job running multiple times. And if it appears that commit in jobs is a really really important use case then we can consider alternatives.

@guewen
Copy link
Member

guewen commented Jan 23, 2026

I'm inclined to merge this so affected users get a clear error instead of hard to diagnose issues with job running multiple times.

Yes, even if crons/jobs are supposed to be idempotent, in case they are not, it can be devastating in some cases if they are run several times concurrently. A clear error is indeed much better than unexpected and erratic behavior.

And it is not blocking anybody because if a cron job is flagged as "run as job" and raises "Commit is forbidden in queue jobs" because of a commit, they can still run it as a normal cron. Thinking about it, we may add some details in the error message, ex "Commit is forbidden in queue jobs. If the current job is a cron running as job, it should be run as a normal job"?

@sbidoul sbidoul force-pushed the 19.0-prevent-commit-in-jobs branch from 6305ae3 to eacc671 Compare January 23, 2026 09:48
This would release the job lock, causing spurious restarts by the dead jobs requeuer.
@sbidoul sbidoul force-pushed the 19.0-prevent-commit-in-jobs branch from eacc671 to adc7d22 Compare January 23, 2026 09:50
@sbidoul sbidoul marked this pull request as ready for review January 23, 2026 09:50
job.store()
env.flush_all()
# TODO refactor, the relation between env and job.env is not clear
assert env.cr is job.env.cr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially was trying assert env is job.env but that fails. I don't quite understand why, but that's unrelated to this PR. What is important is that job.perform() uses the same transaction as the one that is commited with env.cr.commit() 5 lines below.

@sbidoul
Copy link
Member Author

sbidoul commented Jan 23, 2026

This is now ready. I implemented your error message suggestion and added a way to test this interactively.

Copy link
Member

@guewen guewen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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.

3 participants