-
Notifications
You must be signed in to change notification settings - Fork 165
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 regression causing navigation properties to be auto-expanded in typeless scenarios #1424
base: main
Are you sure you want to change the base?
Fix regression causing navigation properties to be auto-expanded in typeless scenarios #1424
Conversation
e7c76b8
to
56b8452
Compare
@@ -117,6 +117,7 @@ public virtual async Task WriteDeltaObjectInlineAsync(object graph, IEdmTypeRefe | |||
} | |||
else | |||
{ | |||
writeContext.IsDelta = true; |
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.
Are we using these method calls to determine when the writeContext.isDelta
is set? What if someone overrides these methods? They'll have to set this property explicitly? What happens if they don't?
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.
@ElizabethOkerio , in #1413, I solved the same bug with a simple type comparison that only modifies one function in one file.
It's practically a one-liner and I would appreciate it if someone could review it. I think it's the most viable fix for this problem. I also added some tests very specific to the reported use-case.
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.
@ElizabethOkerio Following our offline discussion, I have addressed the issue by setting the property from the output formatter where the serializer context is initialized
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 TypelessDataModel
you created here under seems very similar to the one under Untyped
. Are you sure your new tests wouldn't be well suited to that folder?
In fact, your entire Typeless
folder seems very similar to the Untyped
folder.
Meanwhile, the existing Typeless
folder looks very different from this so adding these tests to that folder would be a drastic change.
…ypeless scenarios
1f6386e
to
7676eb1
Compare
@anasik I went through the Untyped folder and I don't see a significant overlap. As a matter of fact, the Edm model in the Untyped folder is typed. In addition, the Typeless folder already had existing tests for typeless scenario |
Fixes #1412
Fix regression causing navigation properties to be auto-expanded in typeless scenarios
The challenge we face is that
EdmEntityObject
,EdmComplexObject
,EdmDeltaResourceObject
,EdmDeltaComplexObject
, andEdmDeltaDeletedResourceObject
(together with their typedinternal
equivalentsTypedEdmEntityObject
andTypedEdmComplexObject
) all implemementIDelta
,IDeltaSetItem
, andIEdmChangedObject
interfaces directly or indirectly.Illustration:
Result:
For the above reason, you can't tell by interrogating the object itself where it's a delta resource - specifically for
EdmEntityObject
andEdmComplexObject
that can be present in both delta and non-delta payloads.What this basically means, is that if you have a controller action like the typeless scenario below, where
Customer
is a navigation property, the navigation property is auto-expanded whether or not there's an$expand
on the URL:The buggy logic is here:
AspNetCoreOData/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs
Line 497 in c60d9e0
We use the
ODataResourceSerializer
to serialize both delta and non-delta payloads. When the above statement is evaluated, it'll always return true for nearly all (if not all) typeless Edm objects, including those in the code sample above, that shouldn't be serialized as a delta.Telling whether an object is a delta or non-delta resource in typeless scenarios becomes a dicey affair.
I propose in this pull request to use the serializer context (via
ODataSerializerContext
) to indicate whether its a delta payload being written or not.This change fixes the regression and addresses the challenge described above.