[17.0][Question] Does job queue lock the related record in the database?
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?
Normally queue_job does not lock other records than the jobs themselves.
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.
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.
There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.
@orfisko can you pls suggest me, how to get out of this issue?
@sarthakmetazone , job queue does not lock. It had to do with my internal logic. You need to be very careful with computed fields and other implicit dependencies that get triggered when record get updated.