-
-
Notifications
You must be signed in to change notification settings - Fork 256
[connection] Fix update_config task incorrectly detecting itself as d… #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[connection] Fix update_config task incorrectly detecting itself as d… #1206
Conversation
…uplicate openwisp#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 openwisp#1204
📝 WalkthroughWalkthroughThe PR fixes a Celery task self-detection bug in update_config. _is_update_in_progress now accepts an optional current_task_id to exclude the caller when scanning active Celery tasks. update_config is converted to a bound task (bind=True) so it passes self.request.id to the checker and avoids false-positive detection of itself. Tests were added to validate _is_update_in_progress behavior across scenarios (excluding current task, detecting other tasks for the same device, different-device cases, and no active tasks). Sequence Diagram(s)sequenceDiagram
participant API as Client/API
participant Broker as Celery Broker
participant Worker as Celery Worker
participant Inspector as current_app.control.inspect
participant DB as Database
API->>Broker: enqueue update_config(device_id)
Broker->>Worker: deliver task
Worker->>Inspector: active() -> list of active tasks
Inspector-->>Worker: active tasks list
Worker->>Worker: _is_update_in_progress(device_id, current_task_id=self.request.id)
alt another worker running same device
Worker-->>Worker: returns True (skip execution)
else no other worker running same device
Worker->>DB: apply configuration update
DB-->>Worker: ack
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-01-15T15:05:49.557ZApplied to files:
📚 Learning: 2026-01-15T15:07:17.354ZApplied to files:
🧬 Code graph analysis (1)openwisp_controller/connection/tests/test_tasks.py (2)
⏰ 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). (11)
🔇 Additional comments (3)
✏️ Tip: You can disable this entire section by setting 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical bug where the update_config Celery task incorrectly detected itself as another running task, causing it to skip execution. The fix adds task binding and current task ID exclusion logic to properly differentiate between the current task and other running tasks.
Changes:
- Modified
_is_update_in_progress()to accept an optionalcurrent_task_idparameter and skip the current task when checking for active duplicate tasks - Updated
update_configtask to usebind=Truedecorator and passself.request.idto_is_update_in_progress() - Added comprehensive unit tests covering the bug scenario, the fix, and various edge cases
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| openwisp_controller/connection/tasks.py | Adds bind=True to task decorator, adds current_task_id parameter to _is_update_in_progress(), and implements logic to skip current task when checking for duplicates |
| openwisp_controller/connection/tests/test_tasks.py | Adds new test class TestIsUpdateInProgress with 5 comprehensive test cases covering the bug, fix, and edge cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.assertTrue( | ||
| result, | ||
| ) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion has an unnecessary trailing comma that is inconsistent with the existing test style in this file. The existing assertions (e.g., lines 68-69) don't use trailing commas for single-argument method calls. Consider removing the trailing comma for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback
| self.assertFalse( | ||
| result, | ||
| ) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion has an unnecessary trailing comma that is inconsistent with the existing test style in this file. The existing assertions (e.g., lines 68-69) don't use trailing commas for single-argument method calls. Consider removing the trailing comma for consistency.
| self.assertTrue( | ||
| result, | ||
| ) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion has an unnecessary trailing comma that is inconsistent with the existing test style in this file. The existing assertions (e.g., lines 68-69) don't use trailing commas for single-argument method calls. Consider removing the trailing comma for consistency.
| self.assertFalse( | ||
| result, | ||
| ) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion has an unnecessary trailing comma that is inconsistent with the existing test style in this file. The existing assertions (e.g., lines 68-69) don't use trailing commas for single-argument method calls. Consider removing the trailing comma for consistency.
736044c to
cca1aa2
Compare
…uplicate openwisp#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 openwisp#1204
cca1aa2 to
010ba62
Compare
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:
Fixes #1204
Checklist
Reference to Existing Issue
Closes #1204 .