-
Notifications
You must be signed in to change notification settings - Fork 351
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
Fix ArgumentException in ProjectPlanCompiler caused by missing materializerContext argument in dynamic calls #2535
Fix ArgumentException in ProjectPlanCompiler caused by missing materializerContext argument in dynamic calls #2535
Conversation
.Select(c => new Computer | ||
{ | ||
ComputerId = c.ComputerId, | ||
ComputerDetail = c.ComputerDetail == null ? null : c.ComputerDetail, |
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 line is interesting, what does the ternary operator give us here?
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 ternary operator here is used to force the ProjectPlanCompiler
to call the method ProjectionCheckValueForPathIsNull
, which is the one that had the bug. In this case, the result of that expression will be the value of c.ComputerDetail
since it's not null. But the key thing here I believe is the null check against a nested EntityType.
@@ -788,6 +789,24 @@ public void Linq_ProjectPropertiesFromEntityandExpandedEntity() | |||
this.EnqueueTestComplete(); | |||
} | |||
|
|||
[Fact] | |||
public async Task Linq_ProjectPropertiesFromEntityWithConditionalNullCheckOnExpandedEntity() |
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.
Would this test be the one that fails without your other changes? The LINQ query wasn't generating an expression with the materializer?
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.
Yes, it was failing without my changes. It was throwing an ArgumentException
because the ProjectPlanCompiler
was generating a dynamic call to ProjectionCheckValueForPathIsNull
without passing the required materializerContext
argument.
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 PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
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.
Issues
*This pull request fixes #2531
Description
The
ProjectionPlanCompiler
andGroupByProjectionCompiler
class call methods of theODataEntityMaterializerInvoker
dynamically using reflection/dynamic IL generation. Since the PR that refactored theMaterializerCache
, many materializer static methods needed to adjusted to accept anIODataMaterializerContext
as input. 2 methods inProjectionPlanCompiler
expect a materializer context as the last argument:ProjectionCheckValueForPathIsNull
andProjectionDynamicValueForPath
.ProjectionPlanCompiler
calls both methods, but did not pass the materializer context to theProjectionCheckValueForPathIsNull
. There was not test covering this method, so we didn't notice. This method is called when there's a conditional check against a nested navigation property in the LINQ query. I've added a test and fixed it.I've also done some additional refactoring (replacing string literals of method names with
nameof
) and implementing suggestions @corranrogue9 added to this PRChecklist (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.