From 9b328c0c38350d7e45a1491f47efabf90ac73f53 Mon Sep 17 00:00:00 2001 From: diaxoaine <42137630+diaxoaine@users.noreply.github.com> Date: Tue, 5 May 2026 22:44:07 +0700 Subject: [PATCH] fix: TaskTimout and TaskRateLimit should pass workername to error_reason --- flower/api/control.py | 4 ++-- tests/unit/api/test_control.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/flower/api/control.py b/flower/api/control.py index cd38aad8d..41f39c361 100644 --- a/flower/api/control.py +++ b/flower/api/control.py @@ -470,7 +470,7 @@ def post(self, taskname): else: logger.error(response) self.set_status(403) - reason = self.error_reason(taskname, response) + reason = self.error_reason(workername, response) self.write(f"Failed to set timeouts: '{reason}'") @@ -527,5 +527,5 @@ def post(self, taskname): else: logger.error(response) self.set_status(403) - reason = self.error_reason(taskname, response) + reason = self.error_reason(workername, response) self.write(f"Failed to set rate limit: '{reason}'") diff --git a/tests/unit/api/test_control.py b/tests/unit/api/test_control.py index 5c3198c5e..4eb279bee 100644 --- a/tests/unit/api/test_control.py +++ b/tests/unit/api/test_control.py @@ -109,6 +109,18 @@ def test_task_timeout(self): 'celery.map', hard=3.1, soft=1.2, destination=['foo'], reply=True) + def test_task_timeout_failure_returns_worker_error_message(self): + celery = self._app.capp + celery.control.time_limit = MagicMock( + return_value=[{'foo': {'error': 'time limits not supported'}}]) + + r = self.post( + '/api/task/timeout/celery.map', + body={'workername': 'foo', 'hard': 3.1, 'soft': 1.2} + ) + self.assertEqual(403, r.code) + self.assertEqual(b"Failed to set timeouts: 'time limits not supported'", r.body) + def test_task_ratelimit(self): celery = self._app.capp celery.control.rate_limit = MagicMock( @@ -131,6 +143,16 @@ def test_task_ratelimit_non_integer(self): celery.control.rate_limit.assert_called_once_with( 'celery.map', '11/m', destination=['foo'], reply=True) + def test_task_ratelimit_failure_returns_worker_error_message(self): + celery = self._app.capp + celery.control.rate_limit = MagicMock( + return_value=[{'foo': {'error': 'Invalid rate limit string'}}]) + + r = self.post('/api/task/rate-limit/celery.map', + body={'workername': 'foo', 'ratelimit': 'garbage'}) + self.assertEqual(403, r.code) + self.assertEqual(b"Failed to set rate limit: 'Invalid rate limit string'", r.body) + def test_param_escape(self): app = self._app.capp app.control.broadcast = MagicMock(