Reverse processing order of setters in query generator#37323
Open
SerhiiKozachenko wants to merge 2 commits intodotnet:mainfrom
Open
Reverse processing order of setters in query generator#37323SerhiiKozachenko wants to merge 2 commits intodotnet:mainfrom
SerhiiKozachenko wants to merge 2 commits intodotnet:mainfrom
Conversation
Refactor processing of method call expressions in setters.
Remove incorrect double-addition of properties during tree traversal
Author
|
@dotnet-policy-service agree |
Member
|
@SerhiiKozachenko what's the problem this is solving exactly, and why is this needed? When submitting a PR, please include at least a minimal description of what it's for. |
Author
|
@roji I have updated description with more info, please check. |
249ae47 to
6b86657
Compare
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.
Refactor processing of method call expressions in setters.
Problem it solves:
ExecuteUpdateAsyncwithSetPropertychain generates reversed parameters in AOT Interceptors, causing InvalidCastException.When running
dotnet ef dbcontext optimizewith--precompile-queriesand--nativeaot, the generated interceptor code for anExecuteUpdateAsyncchain appears to process theSetPropertycalls in reverse order (Last-In-First-Out) instead of source order.This results in a mismatch between the parameter expected by the generated SQL and the value supplied by the interceptor.
Steps to Reproduce:
ExecuteUpdateAsynccall with multipleSetPropertycalls of different types.dotnet ef dbcontext optimize --precompile-queries --nativeaot ...Expected Behavior: The interceptor should map
Expressions[0]to the first property (IsDeleted) andExpressions[1]to the second (LastModified), matching the source order.Actual Behavior: The generated code assumes
Expressions[0]corresponds to the last property written (LastModified/now), effectively reversing the parameters.Runtime Exception: Because
Expressions[0](Boolean) is being passed into the parameter expectingDateTime(TimestampTz), Npgsql throws a cast exception:Proposed Fix: The issue appears to be in
PrecompiledQueryCodeGenerator.ProcessExecuteUpdate. The method iterates over theMethodCallExpressiontree (which is nested inside-out) but does not reverse the order before building the setters array.Using a
Stack<MethodCallExpression>to collect and then reverse the calls fixes the issue by ensuring setters are added in source code order (First -> Last).