From 05a0b221d1ce5039ac1bbedf995e792c4d84f562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 2 May 2023 14:34:37 +0200 Subject: [PATCH] Lock cron table at the transaction starts If the lock is not taken at the transaction starts since c8771e45b861 an exception is raised. Closes #12248 --- trytond/trytond/ir/cron.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trytond/trytond/ir/cron.py b/trytond/trytond/ir/cron.py index 500ec45229..4561347ca6 100644 --- a/trytond/trytond/ir/cron.py +++ b/trytond/trytond/ir/cron.py @@ -161,10 +161,11 @@ class Cron(DeactivableMixin, ModelSQL, ModelView): logger.info('cron started for "%s"', db_name) now = datetime.datetime.now() retry = config.getint('database', 'retry') - with transaction.start(db_name, 0, context={'_skip_warnings': True}): + with transaction.start( + db_name, 0, context={'_skip_warnings': True}, + _lock_tables=[cls._table]): pool = Pool() Error = pool.get('ir.error') - cls.lock() crons = cls.search(['OR', ('next_call', '<=', now), ('next_call', '=', None),