-
Notifications
You must be signed in to change notification settings - Fork 569
Remove pre-emptive constraint validation in import merge operations #5215
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: personal/v-shahamad/Fix_for_Import_to_return_proper_message_in_400_2
Are you sure you want to change the base?
Remove pre-emptive constraint validation in import merge operations #5215
Conversation
…lure Co-authored-by: feordin <298148+feordin@users.noreply.github.com>
Co-authored-by: feordin <298148+feordin@users.noreply.github.com>
Co-authored-by: feordin <298148+feordin@users.noreply.github.com>
…uplication Co-authored-by: feordin <298148+feordin@users.noreply.github.com>
…entation Co-authored-by: feordin <298148+feordin@users.noreply.github.com>
| using System.Data; | ||
| using System.Diagnostics; | ||
| using System.Globalization; | ||
| using System.Linq; |
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.
There are a lot of style errors, I cannot build locally.
| return _importErrorSerializer.Serialize( | ||
| resources.First().Index, | ||
| detailedError, | ||
| resources.First().Offset); |
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.
It is not clear why error message is attributed to the first resource in the batch.
| e.Contains("Database constraint", StringComparison.OrdinalIgnoreCase))) | ||
| { | ||
| _logger.LogWarning("Constraint violation detected during import. Aborting further processing to conserve resources."); | ||
| throw new InvalidOperationException("Import aborted due to constraint violation. See error logs for details."); |
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.
It is not clear how invalid operation can translate to bad request
| } | ||
|
|
||
| [Fact] | ||
| public async Task GivenImportInput_WhenConstraintViolationOccurs_ThenImportShouldAbort() |
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.
Maybe it is valid, but what is missing is E2E test.
SergeyGaluzo
left a 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.
please address my comments
Per PR #5050 feedback: pre-emptive C# constraint validation adds compute overhead on every merge operation and duplicates database constraint logic. This change defers validation to SQL Server, catches constraint violations (error 547) only when they occur, and aborts import immediately on first error.
Changes
SqlServerFhirDataStore.cs
ValidateConstraintViolationsmethod (~160 lines of C# validation logic)ExtractConstraintViolationDetailsto parse SQL exception messages:ImportResourcesAsyncexception handling to catch constraint violations and return formatted errorsSqlImporter.cs
ImportResourcesInBufferImportProcessingJobTests.cs
Example
Before:
After:
Impact
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
microsofthealthoss.pkgs.visualstudio.comdotnet build ./src/Microsoft.Health.Fhir.SqlServer/Microsoft.Health.Fhir.SqlServer.csproj -c Release(dns block)/opt/hostedtoolcache/CodeQL/2.23.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp(dns block)/home/REDACTED/work/fhir-server/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/fhir-server/fhir-server/Microsoft.Health.Fhir.sln --packages /home/REDACTED/work/fhir-server/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/fhir-server/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/fhir-server/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.