Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][Question] Does job queue lock the related record in the database? #706

Open
orfisko opened this issue Nov 5, 2024 · 3 comments
Open
Labels

Comments

@orfisko
Copy link

orfisko commented Nov 5, 2024

When using queue job (thanks btw, excellent addon) I notice that I get these errors quite often:
2024-10-23 06:52:13,986 21661 ERROR kastenman odoo.sql_db: bad query: UPDATE "product_product" SET "write_date" = '2024-10-23 06:51:40.258346', "write_uid" = 1 WHERE id IN (9350)
ERROR: could not serialize access due to concurrent update

Thing is, I use job queue to fetch an image from a website that takes a couple of seconds to load, so there is a relatively long time between the beginning of the job and the end. In the meantime, all sorts of other changes could happen on the related product product model record.
So, can someone tell me whether this is potentially due to queue job and, hence, I should seek to shorten the time needed to run the job?

@sbidoul
Copy link
Member

sbidoul commented Mar 4, 2025

Normally queue_job does not lock other records than the jobs themselves.

@amh-mw
Copy link
Contributor

amh-mw commented Mar 4, 2025

I see a fair number of serialization failures, especially for my jobs that run massively parallel. If your external calls (such as to download the image) are not mutating anything, I would just try again:

except SerializationFailure as e:
    self.logger.exception(e)
    raise RetryableJobError(e)

Another strategy might be to break your job into pieces. For example, change your job to download the image then create a second job that updates the database. That way you don't have a transaction open for a long time. I have a number of order of operations issues when importing data from external systems that I solve like this.

@orfisko
Copy link
Author

orfisko commented Mar 4, 2025

The thing is, from the documentation I gather that with job queue I can only schedule it by linking it to a model record? So using queue job without it being attached to a model record is not clear to me. In any case, I managed to solve the serialization issue after a very long dig around by removing a custom depends on my model which was updating stuff under the hood. So queue job was not causing it as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants