From eb3501d602648f62f5895438024a3e805b652cba Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Wed, 17 Apr 2024 18:01:51 +0200 Subject: [PATCH] [FIX] queue_job: fix exception msg handling 'name' attributes for odoo's exception has been deprecated and produces a warning message. This commit fixes the behavior --- queue_job/controllers/main.py | 4 +++- queue_job/tests/__init__.py | 1 + queue_job/tests/test_run_rob_controller.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 queue_job/tests/test_run_rob_controller.py diff --git a/queue_job/controllers/main.py b/queue_job/controllers/main.py index fce3049fa0..f9d54fed0f 100644 --- a/queue_job/controllers/main.py +++ b/queue_job/controllers/main.py @@ -162,7 +162,9 @@ def _get_failure_values(self, job, traceback_txt, orig_exception): exception_name = orig_exception.__class__.__name__ if hasattr(orig_exception, "__module__"): exception_name = orig_exception.__module__ + "." + exception_name - exc_message = getattr(orig_exception, "name", str(orig_exception)) + exc_message = ( + orig_exception.args[0] if orig_exception.args else str(orig_exception) + ) return { "exc_info": traceback_txt, "exc_name": exception_name, diff --git a/queue_job/tests/__init__.py b/queue_job/tests/__init__.py index 2fdff496bc..1062acdc25 100644 --- a/queue_job/tests/__init__.py +++ b/queue_job/tests/__init__.py @@ -1,3 +1,4 @@ +from . import test_run_rob_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_rob_controller.py new file mode 100644 index 0000000000..bb63bc82ec --- /dev/null +++ b/queue_job/tests/test_run_rob_controller.py @@ -0,0 +1,17 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + +from ..controllers.main import RunJobController +from ..job import Job + + +class TestRunJobController(TransactionCase): + def test_get_failure_values(self): + method = self.env["res.users"].mapped + job = Job(method) + ctrl = RunJobController() + rslt = ctrl._get_failure_values(job, "info", Exception("zero", "one")) + self.assertEqual( + rslt, {"exc_info": "info", "exc_name": "Exception", "exc_message": "zero"} + )