Skip to content
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 the issue when read nested resource untyped in the request #2179

Merged
merged 2 commits into from
Sep 14, 2021

Conversation

xuzhg
Copy link
Member

@xuzhg xuzhg commented Sep 3, 2021

Issues

*This pull request fixes #2165

Description

  • If we have a nested resource whose property name is wrong case or its undeclared property,
  • When we put that property in to the request body, ODL can't read it as Untyped even we set the ReadUntypedAsString=false.
  • Since we understand it's undeclared property, can we directly read it as normal untyped value.
  • This is a simple fix for this issue

Checklist (Uncheck if it is not completed)

  • [x ] Test cases added
  • [x ] Build and test with one-click build and test script passed

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.

@@ -9,6 +9,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<RestorePackages>true</RestorePackages>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can ignore this change. It seems I have to add this configuration at my side to make the VS happen.


using (var msgReader = readRequest ?
new ODataMessageReader((IODataResponseMessage)message, readerSettings, this.serverModel) :
new ODataMessageReader((IODataResponseMessage)message, readerSettings, this.serverModel))
Copy link
Contributor

@gathogojr gathogojr Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between the consequent and the alternative expressions here? #Resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 -- should line 90 cast message to IODataRequestMessage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Thanks.

? ReadExpandedResourceSetNestedResourceInfo(resourceState, null, payloadTypeReference.ToStructuredType(), propertyName, /*isDeltaResourceSet*/ false)
: ReadEntityReferenceLinksForCollectionNavigationLinkInRequest(resourceState, null, propertyName, /*isExpanded*/ true);
readerNestedResourceInfo =
ReadExpandedResourceSetNestedResourceInfo(resourceState, null, payloadTypeReference.ToStructuredType(), propertyName, /*isDeltaResourceSet*/ false);
Copy link
Contributor

@gathogojr gathogojr Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding, how does removing the alternative expression fix the issue? #Pending

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuzhg, please correct my understanding if wrong, but just to make sure that I understand the change --

The old code assumed that only links would ever be sent in a request payload, so it didn't support reading nested content.

In fact, it should be valid to have nested content in a request payload as well as a response payload, so removing the special case code for request payload handles nested content (whether links or actual content) for both cases.

Right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
For "normal" (aka declared) property, the process never goes into this method.

For "undeclared" property, since it's undeclared, we don't know the type. Since, we don't know the type, why shall we treat it as entity/entity reference if it's a request payload.

So, I think in the "undeclared" property reading, we should read it as nested resource info no matter it's request or response.

Copy link
Member

@mikepizzo mikepizzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see minor comments. Assuming the behavior doesn't change for reading nested links in a request payload, I'm fine with the change.


using (var msgReader = readRequest ?
new ODataMessageReader((IODataResponseMessage)message, readerSettings, this.serverModel) :
new ODataMessageReader((IODataResponseMessage)message, readerSettings, this.serverModel))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 -- should line 90 cast message to IODataRequestMessage?

}
else
{
readerNestedResourceInfo = this.ReadingResponse
? ReadExpandedResourceNestedResourceInfo(resourceState, null, propertyName, payloadTypeReference.ToStructuredType(), this.MessageReaderSettings)
Copy link
Member

@mikepizzo mikepizzo Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are "ReadExpandedResourceNestedResourceInfo"
and "ReadEntityReferenceLinksForCollectionNavigationLinkInRequest" still used, or can those methods be deleted? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikepizzo I think ReadExpandedResourceNestedResourceInfo is still being used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is only in 'InnerReadUndeclaredProperty', We are in the method because It's "Undeclared" property.
For normal property, 'ReadEntityReferenceLinksForCollectionNavigationLinkInRequest' and other methods are still in use.

@@ -425,15 +425,12 @@ protected ODataJsonLightReaderNestedResourceInfo InnerReadUndeclaredProperty(IOD
ValidateExpandedNestedResourceInfoPropertyValue(this.JsonReader, isCollection, propertyName, payloadTypeReference);
if (isCollection)
{
readerNestedResourceInfo = this.ReadingResponse
? ReadExpandedResourceSetNestedResourceInfo(resourceState, null, payloadTypeReference.ToStructuredType(), propertyName, /*isDeltaResourceSet*/ false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that ReadExpandedResourceSetNestedResourceInfo (and ReadExpandedResourceNestedResourceInfo) handle the case of the payload just containing links, and that the developer experience behaves the same for this case?

? ReadExpandedResourceSetNestedResourceInfo(resourceState, null, payloadTypeReference.ToStructuredType(), propertyName, /*isDeltaResourceSet*/ false)
: ReadEntityReferenceLinksForCollectionNavigationLinkInRequest(resourceState, null, propertyName, /*isExpanded*/ true);
readerNestedResourceInfo =
ReadExpandedResourceSetNestedResourceInfo(resourceState, null, payloadTypeReference.ToStructuredType(), propertyName, /*isDeltaResourceSet*/ false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuzhg, please correct my understanding if wrong, but just to make sure that I understand the change --

The old code assumed that only links would ever be sent in a request payload, so it didn't support reading nested content.

In fact, it should be valid to have nested content in a request payload as well as a response payload, so removing the special case code for request payload handles nested content (whether links or actual content) for both cases.

Right?

@xuzhg
Copy link
Member Author

xuzhg commented Sep 13, 2021

No, it doesn't change. The change is only for the Undeclared.


In reply to: 748268333

@pull-request-quantifier-deprecated

This PR has 69 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Small
Size       : +60 -9
Percentile : 27.6%

Total files changed: 6

Change summary by file extension:
.cs : +56 -8
.csproj : +4 -1

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@xuzhg
Copy link
Member Author

xuzhg commented Sep 13, 2021

@mikepizzo @gathogojr are the comments ok for you? Shall I go to merge it?

BingAds is waiting the hot release.

Copy link
Member

@mikepizzo mikepizzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@mikepizzo
Copy link
Member

@xuzhg -- LGTM I am okay to merge.


In reply to: 918666404

@xuzhg xuzhg merged commit 0c446be into master Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ODL should be able to read untyped nested complex types with ReadUntypedAsString=false
4 participants