fix(clinical): detect duplicate schedules by SQL error number#229
Open
rlorenzo wants to merge 1 commit into
Open
fix(clinical): detect duplicate schedules by SQL error number#229rlorenzo wants to merge 1 commit into
rlorenzo wants to merge 1 commit into
Conversation
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().
Bundle ReportBundle size has no change ✅ |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #229 +/- ##
==========================================
- Coverage 44.49% 44.48% -0.01%
==========================================
Files 895 895
Lines 51655 51654 -1
Branches 4812 4813 +1
==========================================
- Hits 22983 22980 -3
- Misses 28108 28110 +2
Partials 564 564
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.