From 84847b15ab01e1cd9a3a7a179865d2569364fce4 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Mon, 26 Oct 2026 15:23:22 +0100 Subject: [PATCH] [FIX] queue_job: remove redundant closing() wrapper And rename test module to remove typo. --- queue_job/jobrunner/runner.py | 16 ++++++++-------- queue_job/tests/__init__.py | 2 +- ..._controller.py => test_run_job_controller.py} | 3 +-- test_queue_job/tests/test_requeue_dead_job.py | 3 +-- 4 files changed, 11 insertions(+), 13 deletions(-) rename queue_job/tests/{test_run_rob_controller.py => test_run_job_controller.py} (97%) diff --git a/queue_job/jobrunner/runner.py b/queue_job/jobrunner/runner.py index 443ef27b26..16bef9bc83 100644 --- a/queue_job/jobrunner/runner.py +++ b/queue_job/jobrunner/runner.py @@ -24,7 +24,7 @@ import selectors import threading import time -from contextlib import closing, contextmanager +from contextlib import contextmanager import psycopg2 import requests @@ -145,14 +145,14 @@ def close(self): def _acquire_master_lock(self): """Acquire the master runner lock or raise MasterElectionLost""" - with closing(self.conn.cursor()) as cr: + with self.conn.cursor() as cr: cr.execute("SELECT pg_try_advisory_lock(%s)", (PG_ADVISORY_LOCK_ID,)) if not cr.fetchone()[0]: msg = f"could not acquire master runner lock on {self.db_name}" raise MasterElectionLost(msg) def _has_queue_job(self): - with closing(self.conn.cursor()) as cr: + with self.conn.cursor() as cr: cr.execute( "SELECT 1 FROM pg_tables WHERE tablename=%s", ("ir_module_module",) ) @@ -181,7 +181,7 @@ def _has_queue_job(self): return True def _initialize(self): - with closing(self.conn.cursor()) as cr: + with self.conn.cursor() as cr: cr.execute("LISTEN queue_job") @contextmanager @@ -195,17 +195,17 @@ def select_jobs(self, where, args): "priority, EXTRACT(EPOCH FROM eta), state " f"FROM queue_job WHERE {where}" ) - with closing(self.conn.cursor("select_jobs", withhold=True)) as cr: + with self.conn.cursor("select_jobs", withhold=True) as cr: cr.execute(query, args) yield cr def keep_alive(self): query = "SELECT 1" - with closing(self.conn.cursor()) as cr: + with self.conn.cursor() as cr: cr.execute(query) def set_job_enqueued(self, uuid): - with closing(self.conn.cursor()) as cr: + with self.conn.cursor() as cr: cr.execute( "UPDATE queue_job SET state=%s, " "date_enqueued=date_trunc('seconds', " @@ -305,7 +305,7 @@ def requeue_dead_jobs(self): the controller receiving the request). """ - with closing(self.conn.cursor()) as cr: + with self.conn.cursor() as cr: query = self._query_requeue_dead_jobs() cr.execute(query) diff --git a/queue_job/tests/__init__.py b/queue_job/tests/__init__.py index 009f183567..a31cc36f8e 100644 --- a/queue_job/tests/__init__.py +++ b/queue_job/tests/__init__.py @@ -1,5 +1,5 @@ from . import test_run_job_controller_http -from . import test_run_rob_controller +from . import test_run_job_controller from . import test_runner_channels from . import test_runner_runner from . import test_delayable diff --git a/queue_job/tests/test_run_rob_controller.py b/queue_job/tests/test_run_job_controller.py similarity index 97% rename from queue_job/tests/test_run_rob_controller.py rename to queue_job/tests/test_run_job_controller.py index 4090c811ea..740e40186d 100644 --- a/queue_job/tests/test_run_rob_controller.py +++ b/queue_job/tests/test_run_job_controller.py @@ -1,5 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from contextlib import closing from unittest.mock import patch from odoo.tests.common import TransactionCase @@ -74,7 +73,7 @@ def failing_job(): # The hook writes on the same partner from another cursor. Its changes # are rolled back on close, and the lock timeout avoids waiting forever. def on_fail(**kwargs): - with closing(self.registry.cursor()) as other_cr: + with self.registry.cursor() as other_cr: other_cr.execute("SET LOCAL lock_timeout = '2s'") other_cr.execute( "UPDATE res_partner SET name = 'Written by hook' WHERE id = %s", diff --git a/test_queue_job/tests/test_requeue_dead_job.py b/test_queue_job/tests/test_requeue_dead_job.py index a267c43c87..2870023cae 100644 --- a/test_queue_job/tests/test_requeue_dead_job.py +++ b/test_queue_job/tests/test_requeue_dead_job.py @@ -1,6 +1,5 @@ # Copyright 2025 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from contextlib import closing from datetime import datetime, timedelta from odoo.tests import tagged @@ -61,7 +60,7 @@ def test_lock(self): job_obj.set_started() job_obj.lock() - with closing(self.env.registry.cursor()) as new_cr: + with self.env.registry.cursor() as new_cr: locks = self.get_locks(job_obj.uuid, new_cr) # Row should be locked