Skip to content

[16.0] Add 'Allow Commit' option on job functions#910

Open
lmignon wants to merge 8 commits intoOCA:16.0from
acsone:16.0-add-optional-new-cr
Open

[16.0] Add 'Allow Commit' option on job functions#910
lmignon wants to merge 8 commits intoOCA:16.0from
acsone:16.0-add-optional-new-cr

Conversation

@lmignon
Copy link
Contributor

@lmignon lmignon commented Mar 17, 2026

Backport of #899

guewen and others added 8 commits March 17, 2026 16:25
It is forbidden to commit inside a job, because it releases the job lock
and can cause it to start again, while still being run, by the dead jobs
requeuer. For some use cases, it may actually be legitimate, or at least
be needed in the short term before actual updates in the code.

A new option on the job function, false by default, allow to run the job
in a new transaction, at the cost of an additional connection +
transaction overhead.

Related to OCA#889
False on new databases, True on existing databases.
Should always be False by default on future versions.
As the controller changes env on Job instances.
@OCA-git-bot
Copy link
Contributor

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

@lmignon lmignon marked this pull request as ready for review March 18, 2026 08:09
Copy link
Contributor

@florian-dacosta florian-dacosta left a comment

Choose a reason for hiding this comment

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

LGTM (tested)

@sbidoul
Copy link
Member

sbidoul commented Mar 26, 2026

@guewen I kind of remember you could set allow_commit in with_delay() in your original implementation. Was that removed on purpose, or is it me who imagined it?

@guewen
Copy link
Member

guewen commented Mar 26, 2026

@sbidoul It was only in your head 😂 I didn't think about that. Do you see a use case for this? For methods that accept a "commit=True" parameter?

@florian-dacosta
Copy link
Contributor

On adapting attachment_queue module, where no queue.job.function was defined, I first tried to pass the allow_commit to the with_delay method here https://github.com/OCA/server-tools/pull/3577/changes#diff-21c8389cfe9291d701d45d4860731ff11ac1ce8ddd2317a07479852488bca7b9R57) I was kind of surprised it was not implemented. But I am not sure it is necessary to change anything about this

@sbidoul
Copy link
Member

sbidoul commented Mar 26, 2026

Yes that was what prompted my question ^.

@guewen
Copy link
Member

guewen commented Mar 26, 2026

I suppose most of the time, we know ahead of time when a job method will/should commit or not, so it makes more sense on the job function. If you had to set .with_delay(allow_commit=True) in all the delayed calls of the job, it's not the place where the parameter should be IMO.

@sbidoul
Copy link
Member

sbidoul commented Mar 27, 2026

@lmignon is this good to go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants