Repository navigation
Add opt-in diagnostic logging for OData query validation failures - #2908
Merged
Merged
Conversation
Condense the verbose <summary> blocks added for the opt-in query validation error logging feature while preserving default values, <see cref> links, and the 'never changes the response' invariant. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 573eb3d9-6fb1-4a5d-8bbf-87c0ddbf3dde
requestQueryData is already dereferenced unconditionally by the preceding QueryValidationRunBeforeActionExecution check, so the 'if (requestQueryData != null)' guard could never be false. Removing it resolves the contradictory non-null/nullable invariant within the method; behavior is unchanged since the guarded branch was always taken. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 573eb3d9-6fb1-4a5d-8bbf-87c0ddbf3dde
Adds two AspNetCore tests for the query-validation diagnostic: one asserting the combined $select+$expand branch of QueryValidationErrorLogger.FormatRequestedQueryOptions, and one that sets a RouteEndpoint and asserts the logged Endpoint route template. Extends the test harness with an optional endpoint parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 573eb3d9-6fb1-4a5d-8bbf-87c0ddbf3dde
Add a test that exercises the post-action validation branch (QueryValidationRunBeforeActionExecution == false) by seeding request state with no OData path so pre-action validation is skipped, then driving OnActionExecuted with an IQueryable result and an invalid $select. Asserts a single diagnostic entry is written with the element type, requested options, and reason. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 573eb3d9-6fb1-4a5d-8bbf-87c0ddbf3dde
xuzhg
previously approved these changes
Jul 27, 2026
xuzhg
approved these changes
Jul 27, 2026
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.
Issues
This pull request fixes #xxx.
Description
Ports the query-validation diagnostic logging feature OData/AspNetCoreOData#1592 to the ASP.NET Core WebApi stack.
What's included
EnableQueryAttribute.EnableQueryValidationErrorLoggingto opt in per action.ODataOptions.EnableQueryValidationErrorLogging+ODataOptions.QueryValidationErrorLogLevel(defaultWarning); an explicit value on the attribute overrides the global value.QueryValidationErrorLoggerthat emits the endpoint route template, queried type, attempted$select/$expand, and the failure reason together with the validation exception, categorized forEnableQueryAttribute.Checklist (Uncheck if it is not completed)
Additional work necessary
If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.