From d1bc2fb66a682629fcb586887446ec9646db2507 Mon Sep 17 00:00:00 2001 From: Archana Vaghasiya Date: Mon, 7 Aug 2023 13:08:28 +0000 Subject: [PATCH] [FIX] base: handle the canceling statement due to lock timeout A cron `Base: Auto-vacuum internal data` is running, which is performing `auto_vacuum`. When the time limit exceeds 10 secs, we face the above issue. Error: LockNotAvailable: canceling statement due to lock timeout This commit solves the above issue by rollback the statement if the `auto_vacuum` time limit exceeds 10 secs. sentry-3938940519 closes odoo/odoo#131193 X-original-commit: f3dc0e12ba22968697d75c011352c0df99d5b5ed Signed-off-by: Fabien Pinckaers (fp) Signed-off-by: Archana Vaghasiya (arva) --- odoo/addons/base/models/ir_attachment.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index 116d55fe3be..ce7d38ee723 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -9,6 +9,7 @@ import itertools import logging import mimetypes import os +import psycopg2 import re import uuid @@ -174,7 +175,11 @@ class IrAttachment(models.Model): # but only attempt to grab the lock for a little bit, otherwise it'd # start blocking other transactions. (will be retried later anyway) cr.execute("SET LOCAL lock_timeout TO '10s'") - cr.execute("LOCK ir_attachment IN SHARE MODE") + try: + cr.execute("LOCK ir_attachment IN SHARE MODE") + except psycopg2.errors.LockNotAvailable: + cr.rollback() + return False self._gc_file_store_unsafe()