Skip to content

Conversation

@piyushdev04
Copy link
Contributor

@piyushdev04 piyushdev04 commented Jan 26, 2026

The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered.

Fixes #1204

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • N/A I have updated the documentation.

Reference to Existing Issue

Closes #1204.

Description of Changes

  • Updated _is_update_in_progress to ignore the currently executing Celery task by comparing task IDs.

  • Added tests to verify behavior for:

    • Same worker (should not skip execution)
    • Different worker (should skip execution)
    • No active tasks
    • Different device

Verification / Tests:

  • On master (old code), test_is_update_in_progress_same_worker fails.
  • On this branch, all tests pass:
    openwisp_controller/connection/tests/test_tasks.py::TestIsUpdateInProgress PASSED [100%]

…1204

The _is_update_in_progress function was incorrectly detecting the
current Celery task as another running task, causing update_config
to exit early. This fix excludes the current task by comparing task IDs,
ensuring only other instances for the same device are considered.

Fixes openwisp#1204
@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

Walkthrough

This change fixes task self-detection in Celery deduplication logic. _is_update_in_progress(device_id) now reads the current task id from current_task.request.id and ignores that id when comparing active tasks returned by inspect().active(). It returns True only if there is a different running task with the same name and device id. A new test suite exercises same-worker, different-worker, no-active-tasks, and different-device scenarios.

Sequence Diagram(s)

sequenceDiagram
participant Worker as Current Worker
participant Celery as Celery Inspect
participant Other as Other Worker
Worker->>Celery: inspect.active()
Celery-->>Worker: list of active tasks (each with worker, id, name, kwargs)
Worker->>Worker: get current_task.request.id
alt Old logic (pre-change)
    Worker->>Worker: if any active task matches name+device -> return True
else New logic (post-change)
    Worker->>Worker: ignore active task with id == current_task.id
    Worker->>Worker: if any remaining active task matches name+device -> return True
end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing the _is_update_in_progress function to ignore the current task when checking active tasks, directly addressing issue #1204.
Description check ✅ Passed The PR description covers all required sections: references the issue, explains the problem and fix, lists changes made, documents tests added, and confirms manual testing and test results.
Linked Issues check ✅ Passed The code changes fully address the requirement in issue #1204: the _is_update_in_progress function now correctly excludes the current task by comparing task IDs, preventing self-detection and ensuring proper execution flow.
Out of Scope Changes check ✅ Passed All changes in the PR are directly scoped to fixing issue #1204: the function logic update and accompanying test cases with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c989ae and 12c0178.

📒 Files selected for processing (1)
  • openwisp_controller/connection/tasks.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • openwisp_controller/connection/tasks.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Python==3.11 | django~=4.2.0
  • GitHub Check: Python==3.10 | django~=5.1.0
  • GitHub Check: Python==3.11 | django~=5.1.0
  • GitHub Check: Python==3.12 | django~=5.1.0
  • GitHub Check: Python==3.13 | django~=5.1.0
  • GitHub Check: Python==3.12 | django~=4.2.0
  • GitHub Check: Python==3.12 | django~=5.2.0
  • GitHub Check: Python==3.13 | django~=5.2.0

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 26, 2026
…tive tasks - openwisp#1204

The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios.

Fixes openwisp#1204
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 26, 2026
…ive tasks - openwisp#1204

The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios.

Fixes openwisp#1204
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 26, 2026
@nemesifier nemesifier changed the title [connection] Ignore current task when checking active tasks #1204 [fix] Ignore current task when checking active tasks #1204 Jan 26, 2026
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up @piyushdev04.

Are you sure the tests fail without the patch? I haven't tried yet but will try soon, please double check and ensure the failure message is clear when tests fail.

See my other comment below.

Comment on lines 26 to 27
else:
current_task_id = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else:
current_task_id = None

Not needed

for task in task_list:
if task["name"] == _TASK_NAME and str(device_id) in task["args"]:
return True
if task.get("id") != current_task_id:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid nesting this and add it to the previous if, we should probably rewrite this using all() https://docs.python.org/3/library/functions.html#all

@coveralls
Copy link

coveralls commented Jan 26, 2026

Coverage Status

coverage: 98.64% (-0.001%) from 98.641%
when pulling 7394bd8 on piyushdev04:issues/1204-celery-update-config-self-detection
into cbdb3c6 on openwisp:master.

…ive tasks - openwisp#1204

The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios.

Fixes openwisp#1204
…ive tasks - openwisp#1204

The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios.

Fixes openwisp#1204
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 26, 2026
@piyushdev04
Copy link
Contributor Author

Hi @nemesifier , I checked locally on master and TestIsUpdateInProgress.test_is_update_in_progress_same_worker does fail without the patch, and it passes with the patch applied. All other tests for this function also pass.

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piyushdev04 can you verify that this patch work when there are multiple celery workers? (launch the celery workers with --concurrency 4 flag).

Have you tested the fix manually?

except ObjectDoesNotExist as e:
logger.warning(f'update_config("{device_id}") failed: {e}')
return
if _is_update_in_progress(device_id):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's log at INFO level here to convey that the task was skipped because another task is in progress.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 8, 2026
…ive tasks openwisp#1204

The _is_update_in_progress function was incorrectly detecting the current
Celery task as another running task, causing update_config to exit early.

This fix excludes the current task by comparing task IDs, ensuring only
other instances for the same device are considered. Added tests to cover
same worker (should not skip) and different worker (should skip) scenarios.

Additionally, added INFO-level logging to convey when a task is skipped
because another task is in progress.

Fixes openwisp#1204
@piyushdev04 piyushdev04 force-pushed the issues/1204-celery-update-config-self-detection branch from bf1ba35 to 3c989ae Compare February 8, 2026 06:07
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 8, 2026
…ive tasks openwisp#1204

The _is_update_in_progress function was incorrectly detecting the current
Celery task as another running task, causing update_config to exit early.

This fix excludes the current task by comparing task IDs, ensuring only
other instances for the same device are considered. Added tests to cover
same worker (should not skip) and different worker (should skip) scenarios.

Additionally, added INFO-level logging to convey when a task is skipped
because another task is in progress.

Fixes openwisp#1204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Development

Successfully merging this pull request may close these issues.

[bug] Celery worker skips execution of update_config task due to incorrect self-detection

4 participants