Eliminate code duplication requests between Upsert and Insert #3287
Open
aaronburtle wants to merge 5 commits intomainfrom
Open
Eliminate code duplication requests between Upsert and Insert #3287aaronburtle wants to merge 5 commits intomainfrom
aaronburtle wants to merge 5 commits intomainfrom
Conversation
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates SQL mutation handling so REST upserts (PUT/PATCH) without a PK in the route can reuse the existing insert/update flow: if PKs are absent it behaves like an insert, and if PKs are supplied in the body it can correctly update an existing row. It also adds regression tests to cover keyless PUT/PATCH requests where PKs are provided in the request body.
Changes:
- Promote primary key values from request body into
PrimaryKeyValuePairsfor keyless upsert requests when all PK fields are present. - Treat keyless upsert requests that still lack PKs as effective inserts to avoid generating unsafe UPDATE statements.
- Add cross-DB REST tests for keyless PUT/PATCH upsert behavior when PKs are included in the body.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs | Adds PUT regression tests for keyless routes with PKs in body; minor comment line touched. |
| src/Service.Tests/SqlTests/RestApiTests/Put/PostgreSqlPutApiTests.cs | Adds SQL verification queries for new PUT tests (PostgreSQL). |
| src/Service.Tests/SqlTests/RestApiTests/Put/MySqlPutApiTests.cs | Adds SQL verification queries for new PUT tests (MySQL). |
| src/Service.Tests/SqlTests/RestApiTests/Put/MsSqlPutApiTests.cs | Adds SQL verification queries for new PUT tests (SQL Server). |
| src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs | Adds PATCH regression tests for keyless routes with PKs in body. |
| src/Service.Tests/SqlTests/RestApiTests/Patch/PostgreSqlPatchApiTests.cs | Adds SQL verification queries for new PATCH tests (PostgreSQL). |
| src/Service.Tests/SqlTests/RestApiTests/Patch/MySqlPatchApiTests.cs | Adds SQL verification queries for new PATCH tests (MySQL). |
| src/Service.Tests/SqlTests/RestApiTests/Patch/MsSqlPatchApiTests.cs | Adds SQL verification queries for new PATCH tests (SQL Server). |
| src/Core/Resolvers/SqlMutationEngine.cs | Refactors upsert flow so keyless upserts either use body PKs for UPDATE or fall through to INSERT path. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
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.
Why make this change?
Closes #3209
What is this change?
Allow Upserts coming from REST requests to fall through to the Insert logic when auto-generated primary keys are missing. This eliminates code duplication between these two ops in the
SqlMutationEngineAdd a test to cover the case when we have a PUT/PATCH with keys provided in the request body.
How was this tested?
New test was added to ensure complete coverage over the scenarios introduced with the keyless PUT/PATCH change.
Sample Request(s)
PUT that updates existing row (expects 200 OK):
PUT that inserts new row (expects 201 Created):
PATCH that updates existing row (expects 200 OK):
PATCH that inserts new row (expects 201 Created):