fix(clinical): detect duplicate schedules by SQL error number#229
fix(clinical): detect duplicate schedules by SQL error number#229rlorenzo wants to merge 1 commit into
Conversation
Bundle ReportBundle size has no change ✅ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #229 +/- ##
==========================================
+ Coverage 44.58% 44.60% +0.02%
==========================================
Files 896 896
Lines 51733 51737 +4
Branches 4834 4835 +1
==========================================
+ Hits 23063 23078 +15
+ Misses 28098 28087 -11
Partials 572 572
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Pull request overview
Refines error handling in the Clinical Scheduler’s ScheduleEditService.AddInstructorAsync so that “already scheduled” is only returned for true SQL Server duplicate/unique key violations, using stable SQL error numbers instead of locale-dependent substring matching on exception messages.
Changes:
- Replaces exception message substring matching with SQL Server error-number detection (2627, 2601) to identify duplicate-key violations.
- Adds a focused helper (
IsDuplicateKeyViolation) to unwrap EF/SQL exceptions and checkSqlException.Errors.
384a05b to
06ab238
Compare
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthrough
ChangesDuplicate-key error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/Areas/ClinicalScheduler/Services/ScheduleEditService.cs`:
- Around line 250-252: Add targeted tests for the exception classification logic
in IsDuplicateKeyViolation within ScheduleEditService so both branches are
covered. Create tests that feed the service a duplicate-key SqlException with
error numbers 2627 and 2601 and verify the duplicate-schedule path, plus a
non-duplicate SqlException/DbUpdateException that verifies the generic
database-failure path. Make sure the tests assert the downstream API error
mapping contract stays distinct for these two cases.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 109ef738-ea05-4f15-b163-60f3a498908e
📒 Files selected for processing (1)
web/Areas/ClinicalScheduler/Services/ScheduleEditService.cs
06ab238 to
b9765ea
Compare
b9765ea to
85efd3c
Compare
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai review |
85efd3c to
c881eba
Compare
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/Areas/ClinicalScheduler/Services/ScheduleEditService.cs`:
- Around line 262-269: The duplicate-key detection in IsDuplicateKeyViolation
only checks one inner exception level, which is brittle if the SqlException is
wrapped more than once. Update the method to walk the full exception chain
starting from ex until you find a SqlException, then keep the existing 2627/2601
error-number check so the duplicate-key path still works even with deeper
wrapping.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 55cf54a0-368a-4cd5-9873-058d30a19dea
📒 Files selected for processing (4)
test/ClinicalScheduler/ScheduleEditServiceTest.cstest/ClinicalScheduler/SqlExceptionFactory.cstest/ClinicalScheduler/ToggleThrowContext.csweb/Areas/ClinicalScheduler/Services/ScheduleEditService.cs
c881eba to
84afaba
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Replace locale-fragile message-substring matching with SQL Server error numbers 2627/2601 (unique constraint / duplicate key in a unique index) to decide whether a save failure means the instructor is already scheduled. Other database errors (foreign-key, check constraints) now fall through to the generic message instead of mis-reporting "already scheduled", and the check no longer depends on English error text or a culture-specific ToLower().
84afaba to
9114f3c
Compare
What
In
ScheduleEditService.AddInstructorAsync, the post-SaveChangescatch decides whether a DB failure means "instructor already scheduled" by SQL Server error number (2627 unique-constraint, 2601 duplicate-key-in-unique-index) instead of substring-matching the exception message.Why
The old check matched
"duplicate" / "unique" / "constraint" / "violation of primary key"againstmessage.ToLower(). Two problems:ToLower()plus English error-text matching is culture-sensitive (Turkish-I) and breaks if SQL messages are localized. Error numbers are stable and locale-invariant.Notes
AddInstructorAsync_WithScheduleConflictsand all 2084 tests pass.Developmentvia refactor(codeql): decompose complex conditions + harden Vite web-root check #227; the overlap will be resolved (keeping this version) at the Development merge.