-
Notifications
You must be signed in to change notification settings - Fork 536
fix deadlock in TagConfig endpoints #3372
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: develop
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
care/emr/models/tag_config.py (1)
69-90: Directupdateto persist cache looks correct; confirm skipped save/signals are intentional and consider documentingSwitching to
TagConfig.objects.filter(id=self.id).update( cached_parent_json=self.cached_parent_json )nicely avoids the
save()/post_savecycle that was causing the deadlock, while still doing a single atomic DB UPDATE on just this field. That aligns with the stated PR goal.Two non‑blocking points to double‑check:
- This bypasses
Model.save(), signals, and anyauto_now/updated_atstyle fields onEMRBaseModel. If anything downstream relies on those changing when the cache is refreshed, this behavior will silently diverge from before.- It might be slightly safer/clearer to use the instance’s class/PK and leave a short comment so nobody “helpfully” changes this back to
save()later, e.g.:type(self).objects.filter(pk=self.pk).update( cached_parent_json=self.cached_parent_json ) # NB: use queryset.update() here specifically to avoid save() signals / cache invalidation loops.If those trade‑offs are acceptable, the change itself looks good and should resolve the deadlock.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
care/emr/models/tag_config.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (.cursorrules)
**/*.py: Prioritize readability and maintainability; follow Django's coding style guide (PEP 8 compliance).
Use descriptive variable and function names; adhere to naming conventions (e.g., lowercase with underscores for functions and variables).
Files:
care/emr/models/tag_config.py
**/{models,views,management/commands}/*.py
📄 CodeRabbit inference engine (.cursorrules)
Leverage Django’s ORM for database interactions; avoid raw SQL queries unless necessary for performance.
Files:
care/emr/models/tag_config.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). (1)
- GitHub Check: Test / Test
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3372 +/- ##
===========================================
+ Coverage 73.91% 73.92% +0.01%
===========================================
Files 435 435
Lines 19748 19748
Branches 2138 2138
===========================================
+ Hits 14597 14599 +2
+ Misses 4705 4704 -1
+ Partials 446 445 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Proposed Changes
Cause
GET/LIST endpoints were calling .save(), which triggered the post_save signal used for cache invalidation. Since reads don't change data, they shouldn't invalidate cache. This caused recursive invalidation cascades and deadlocks.
Only PR's with test cases included and passing lint and test pipelines will be reviewed
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.