Skip to content

Commit cca1aa2

Browse files
committed
[connection] Fix update_config task incorrectly detecting itself as duplicate #1204
The _is_update_in_progress function was incorrectly returning True when the only active task was the current task itself, causing the worker to skip execution thinking another worker was handling it. Fixed by: - Adding current_task_id parameter to _is_update_in_progress() - Using bind=True on update_config task to access self.request.id - Excluding the current task when checking for active duplicates - Added unit tests to verify the fix Fixes #1204
1 parent e881eba commit cca1aa2

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

openwisp_controller/connection/tests/test_tasks.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ def test_is_update_in_progress_without_current_task_id(self, mock_app):
116116
# BUG: Without passing current_task_id, the function returns True
117117
# even though the only active task IS the current task
118118
result = _is_update_in_progress(device_id)
119-
self.assertTrue(
120-
result,
121-
)
119+
self.assertTrue(result)
122120

123121
@mock.patch("openwisp_controller.connection.tasks.current_app")
124122
def test_is_update_in_progress_with_current_task_id_excluded(self, mock_app):
@@ -132,9 +130,7 @@ def test_is_update_in_progress_with_current_task_id_excluded(self, mock_app):
132130

133131
# FIX: With current_task_id provided, the function correctly returns False
134132
result = _is_update_in_progress(device_id, current_task_id=current_task_id)
135-
self.assertFalse(
136-
result,
137-
)
133+
self.assertFalse(result)
138134

139135
@mock.patch("openwisp_controller.connection.tasks.current_app")
140136
def test_is_update_in_progress_detects_another_task(self, mock_app):
@@ -161,9 +157,7 @@ def test_is_update_in_progress_detects_another_task(self, mock_app):
161157

162158
# Should return True because another task IS running
163159
result = _is_update_in_progress(device_id, current_task_id=current_task_id)
164-
self.assertTrue(
165-
result,
166-
)
160+
self.assertTrue(result)
167161

168162
@mock.patch("openwisp_controller.connection.tasks.current_app")
169163
def test_is_update_in_progress_no_active_tasks(self, mock_app):
@@ -185,9 +179,7 @@ def test_is_update_in_progress_different_device(self, mock_app):
185179
)
186180

187181
result = _is_update_in_progress(device_id, current_task_id="task-123")
188-
self.assertFalse(
189-
result,
190-
)
182+
self.assertFalse(result)
191183

192184

193185
class TestTransactionTasks(

0 commit comments

Comments
 (0)