-
Notifications
You must be signed in to change notification settings - Fork 313
Add keyless REST PUT/PATCH support for entities with auto-generated primary keys #3150
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
Open
aaronburtle
wants to merge
9
commits into
main
Choose a base branch
from
dev/aaronburtle/AddIdentityKeySupportForPatch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+217
−18
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2e65430
update docs
aaronburtle 0696d6f
add MsSql test support
aaronburtle 9afa09f
update tests
aaronburtle bff31ce
Merge branch 'main' into dev/aaronburtle/AddIdentityKeySupportForPatch
aaronburtle e89741c
fix failing tests
aaronburtle 37094ec
address comments
aaronburtle dc1b95a
help pipeline to pass
aaronburtle ea37d0f
Merge branch 'main' into dev/aaronburtle/AddIdentityKeySupportForPatch
aaronburtle af7d0eb
Merge branch 'main' into dev/aaronburtle/AddIdentityKeySupportForPatch
aaronburtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,9 +120,18 @@ public async Task TestAzureLogAnalyticsFlushServiceSucceed(string message, LogLe | |
|
|
||
| _ = Task.Run(() => flusherService.StartAsync(tokenSource.Token)); | ||
|
|
||
| await Task.Delay(2000); | ||
| // Poll until the log appears (the flusher service needs time to dequeue and upload) | ||
| int maxWaitMs = 10000; | ||
| int pollIntervalMs = 100; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why start with such a low |
||
| int elapsed = 0; | ||
| while (customClient.LogAnalyticsLogs.Count == 0 && elapsed < maxWaitMs) | ||
| { | ||
| await Task.Delay(pollIntervalMs); | ||
| elapsed += pollIntervalMs; | ||
| } | ||
|
|
||
| // Assert | ||
| Assert.IsTrue(customClient.LogAnalyticsLogs.Count > 0, $"Expected at least one log entry after waiting {elapsed}ms, but found none."); | ||
| AzureLogAnalyticsLogs actualLog = customClient.LogAnalyticsLogs[0]; | ||
| Assert.AreEqual(logLevel.ToString(), actualLog.LogLevel); | ||
| Assert.AreEqual(message, actualLog.Message); | ||
|
|
||
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
The conversion to Insert is not gated by “auto-generated PK”. Should it?
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.
Good question, this is OK because our
RequestValidatorwill handle the validation side of things and we keep a clean separation of responsibility.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.
This is indeed a good question. @aaronburtle, I checked with Copilot, and it says "So: autogenerated PKs do not bypass the URL [primaryKeyRoute] requirement for update/upsert/delete. For insert, a URL PK is disallowed regardless, in [RequestValidator.cs:224-232].
public void ValidatePrimaryKey(RestRequestContext context)see this function.You need to fix the exception that we throw there, in cases of Patch/Put to not check for existence of primaryKey in the route if they are autogenerated.
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.
We should be OK, because we are changing the Patch/Put to an insert operation already in
RestServiceif (string.IsNullOrEmpty(primaryKeyRoute) && (operationType is EntityActionOperation.Upsert || operationType is EntityActionOperation.UpsertIncremental)) { operationType = EntityActionOperation.Insert; }And then when we do the validation on lines 224-232 of
RequestValidatorwe expect there to be no Primary Key, so keyless Put Patch should be fine, since we've converted to insert and then have the right behaviorcase EntityActionOperation.Insert: if (!isPrimaryKeyRouteEmpty) { throw new DataApiBuilderException( message: PRIMARY_KEY_INVALID_USAGE_ERR_MESSAGE, statusCode: HttpStatusCode.BadRequest, subStatusCode: DataApiBuilderException.SubStatusCodes.BadRequest); }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.
looks like the conversion to Insert operation happens before we do the Request Validation. In that case, we should be ok with validation. But, then we should be doing the conversion to Insert only when the PKs are autogenerated. Otherwise, we should NOT convert into Insert and continue to throw the exception.
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.
I think we want this behavior because they could include the PKs in the body of the request, in which case we should still be able to do the insert. The logic would be to convert to Insert even for non auto-gen, then the Insert validation logic applies, and if it is non-auto-gen it must include the keys in the body, and only if those keys are missing from the body as well, we would throw.
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.
I know this is effectively going beyond the scope of this underlying issue, however, we get this additional functionality for free just by letting the request validator handle the insert op, so seems worth it.
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.
So after speaking offline we have identified the correct behavior we want, will provide it here for clarity.
In a truly keyless PUT/PATCH, we will convert to insert op, that means no key in URL, no key in body. The Insert validation will just work in this case. It will succeed if we are auto-gen, and fail if we are not. This will require identifying when we have keys in the body when the URL is missing keys.
For PUT/PATCH where the URL is keyless, but we have the keys in the body, we want to use Upsert semantics, so we will not convert to an insert. This will require new validation logic.