🐛(backend) fix race condition in reconciliation requests CSV import#2153
🐛(backend) fix race condition in reconciliation requests CSV import#2153
Conversation
d425857 to
2de0452
Compare
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis pull request addresses a race condition in the CSV import reconciliation workflow. The CHANGELOG.md is updated to document a bug fix for reconciliation requests CSV import. The backend admin file is modified to defer Celery task queuing for Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/backend/core/admin.py`:
- Around line 114-116: The worker task user_reconciliation_csv_import_job should
defensively handle the case where
UserReconciliationCsvImport.objects.get(id=job_id) raises DoesNotExist: update
the task (the function user_reconciliation_csv_import_job in
src/backend/core/tasks/user_reconciliation.py) to wrap the get(...) call in a
try/except catching UserReconciliationCsvImport.DoesNotExist (or the model's
DoesNotExist), log a clear warning including the job_id, and return gracefully
instead of allowing the exception to bubble up.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1e9b5a58-283d-4817-920b-b4bb5ef45c9c
📒 Files selected for processing (2)
CHANGELOG.mdsrc/backend/core/admin.py
8dc3c18 to
d434b95
Compare
|
|
||
| if not change: | ||
| user_reconciliation_csv_import_job.delay(obj.pk) | ||
| transaction.on_commit( |
There was a problem hiding this comment.
The Django documentation says this: If you call on_commit() while there isn’t an open transaction, the callback will be executed immediately.
Maybe I'm wrong, but if you are not in an transaction.atomic block, the callback will be executed immediately. Is it what you want ?
There was a problem hiding this comment.
We are in Django Admin here, which IIRC uses transactions by default (contrary to normal Django views.)
The call to the background task is now wrapped in a on_commit to ensure that it isn't called before the save is finished, in order to avoid race condition issues.
d434b95 to
9405535
Compare
Purpose
The call to the background task is now wrapped in a on_commit to ensure that it isn't called before the save is finished, in order to avoid race condition issues.
Proposal
user_reconciliation_csv_import_jobin atransaction.on_commitonUserReconciliationCsvImportAdmin.save_model()External contributions
Thank you for your contribution! 🎉
Please ensure the following items are checked before submitting your pull request:
git commit --signoff(DCO compliance)git commit -S)<gitmoji>(type) title description## [Unreleased]section (if noticeable change)