AutoExpand does not expand beyond non-default MaxExpansionDepth - #841
Merged
gathogojr merged 1 commit intoFeb 28, 2023
Conversation
gathogojr
requested review from
ElizabethOkerio,
KenitoInc,
habbes,
lisicase,
mikepizzo and
xuzhg
February 16, 2023 08:03
xuzhg
previously approved these changes
Feb 16, 2023
habbes
previously approved these changes
Feb 20, 2023
gathogojr
force-pushed
the
fix/autoexpand-does-not-expand-beyond-non-default-max-expansion-depth
branch
from
February 24, 2023 08:55
250c253 to
2555b3a
Compare
gathogojr
force-pushed
the
fix/autoexpand-does-not-expand-beyond-non-default-max-expansion-depth
branch
from
February 24, 2023 08:57
2555b3a to
ff68ccf
Compare
habbes
approved these changes
Feb 27, 2023
| { | ||
| SelectExpand.LevelsMaxLiteralExpansionDepth = originalSelectExpand.LevelsMaxLiteralExpansionDepth; | ||
| } | ||
| else if (Context.ValidationSettings != null && Context.ValidationSettings.MaxExpansionDepth > 0) |
Contributor
There was a problem hiding this comment.
Out of curiosity, 0 is not a valid max expansion depth?
Contributor
Author
There was a problem hiding this comment.
@habbes What my investigation revealed is that if you set a MaxExpansionDepth of 0, that doesn't get applied - it defaults to configured MaxExpansionDepth of 2. The following won't prohibit expansion currently. That's the reason I used Context.ValidationSettings.MaxExpansionDepth > 0 in this PR to keep it consistent with the current behavior even as I follow up confirm if the current behavior is by design.
The following won't currently have the effect of preventing expansion:
[EnableQuery(MaxExpansionDepth = 0)]
public ActionResult<IEnumerable<Customer>> Get()
{
return customers;
}
xuzhg
approved these changes
Feb 27, 2023
gathogojr
deleted the
fix/autoexpand-does-not-expand-beyond-non-default-max-expansion-depth
branch
February 28, 2023 04:58
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.
Fixes OData/WebApi#2748
We set the default
MaxExpansionDepthwhen theValidatemethod of theODataQueryOptionsobject is called. The problem currently is that when theMaxExpansionDepthis overridden, for instance by assigning the value from theEnableQueryattribute ([EnableQuery(MaxExpansionDepth = 4)]), we call theValidatemethod before theAutoExpandnavigation properties have been added to theSelectExpandQueryOptionobject. For that reason, the specifiedMaxExpansionDepthends up not being respected for the auto-expanded navigation properties.This pull request fixes that by calling
ODataQueryOptions.AddAutoSelectExpandPropertiesprior to validating theSelectExpandquery option.