-
Notifications
You must be signed in to change notification settings - Fork 574
Improve Import Error Handling for Database Constraint Violations #5050
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: main
Are you sure you want to change the base?
Improve Import Error Handling for Database Constraint Violations #5050
Conversation
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Outdated
Show resolved
Hide resolved
…_proper_message_in_400_2
…_proper_message_in_400_2
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.
Adding checks before calling merge adds extra load on app compute for each normal merge call. I suggest running this check only if merge fails with constraint violation. This way there should be zero effect on performance for case when there are not constraint errors.
I do not like having any code duplicated (C# constraint code and the database). Can we get away with reporting some details of SQL error and attributing it to the resource lines in the input file for the batch we processed? This might not be that precise, but we will not have any code duplication.
We also should abort import on first constraint error and should not spend app compute on analyzing all the input resources.
Please add a test for this functionality.
|
Hi @SergeyGaluzo , Thanks for the detailed suggestions. I’ll start implementing these changes accordingly. |
@v-shahzad I would consider "no code duplication" approach if possible. This sounds very attractive, |
…_proper_message_in_400_2
…_proper_message_in_400_2
…constraint exception happens
|
@v-shahzad Please remove any constraint validation from C#. |
…ion message for the batch
…_proper_message_in_400_2
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Outdated
Show resolved
Hide resolved
|
Hi @SergeyGaluzo , I have added the constraint details to the first resource of the batch with the format Error on batch with offset 0 rows from 1 to 3. Insert failed due to the constraint 'CHK_TokenSearchParam_CodeOverflow' on 'TokenSearchParam'. Details: (len([Code])=(256) OR [CodeOverflow] IS NULL). Please suggest me if it matches your expectation or if you would like any changes. |
@v-shahzad This is much better.
|
Thanks for the feedback, @SergeyGaluzo . I’ve made the suggested changes. Please let me know if any further updates are needed. |
…_proper_message_in_400_2
…_proper_message_in_400_2
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirDataStore.cs
Outdated
Show resolved
Hide resolved
| mimetype: application/x-microsoft.net.object.bytearray.base64 | ||
| value : The object must be serialized into a byte array | ||
| value : The object must be serialized into a byte array |
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 make sure that only added lines are marked as changed in diff.
|
Please add import tests for all expected types of constraint violations. |
|
We do not plan to have foreign keys, please remove this section from SQL query. |
|
Please evaluate whether violation of PK/Unique constraints are possible in import. If not, remove corresponding section from SQL query. |
|
Hi @SergeyGaluzo , I’ve removed the checks for primary key and foreign key constraints since we’re only catching exceptions related to overflow constraints. I’ll create a separate user story and PR for the test cases. |
Description
This change introduces a pre-flight validation step within the $import data pipeline to proactively detect and report database constraint violations on a per-resource basis.
Related issues
Addresses AB# 151709
Testing
For now it just contains sample change for one constraint to get approval for the approach
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)