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

Nested $orderby in $select/$expand with built-in/custom function not working #1372

Open
Xriuk opened this issue Dec 13, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@Xriuk
Copy link

Xriuk commented Dec 13, 2024

Assemblies affected
ASP.NET Core OData 8.2.4

Describe the bug
When I try using a built-in or custom function in an $orderby expression inside a $select I get the following exception:

NotImplementedException
   in Microsoft.OData.UriParser.QueryNodeVisitor`1.Visit(ConvertNode nodeIn) in Microsoft.OData.UriParser\QueryNodeVisitor.cs: riga 54
   in Microsoft.OData.UriParser.ConvertNode.Accept[T](QueryNodeVisitor`1 visitor) in Microsoft.OData.UriParser\ConvertNode.cs: riga 28
   in Microsoft.AspNetCore.OData.Query.Validator.OrderByModelLimitationsValidator.Visit(SingleValueFunctionCallNode nodeIn) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\OrderByModelLimitationsValidator.cs: riga 142
   in Microsoft.OData.UriParser.SingleValueFunctionCallNode.Accept[T](QueryNodeVisitor`1 visitor) in Microsoft.OData.UriParser\SingleValueFunctionCallNode.cs: riga 55
   in Microsoft.AspNetCore.OData.Query.Validator.OrderByModelLimitationsValidator.TryValidate(OrderByClause orderByClause, Boolean explicitPropertiesDefined) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\OrderByModelLimitationsValidator.cs: riga 47
   in Microsoft.AspNetCore.OData.Query.Validator.OrderByModelLimitationsValidator.TryValidate(IEdmProperty property, IEdmStructuredType structuredType, OrderByClause orderByClause, Boolean explicitPropertiesDefined) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\OrderByModelLimitationsValidator.cs: riga 39
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.ValidateNestedOrderby(OrderByClause orderByClause, SelectExpandValidatorContext validatorContext) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 405
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.ValidatePathSelectItem(PathSelectItem pathSelectItem, SelectExpandValidatorContext validatorContext) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 303
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.ValidateSelectExpand(SelectExpandClause selectExpandClause, SelectExpandValidatorContext validatorContext) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 102
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 54
   in Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Query\SelectExpandQueryOption.cs: riga 266
   in Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\ODataQueryValidator.cs: riga 106
   in Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\ODataQueryOptions.cs: riga 652
...

Inside an $expand the exception is a bit different:

NotImplementedException
   in Microsoft.OData.UriParser.QueryNodeVisitor`1.Visit(ConvertNode nodeIn) in Microsoft.OData.UriParser\QueryNodeVisitor.cs: riga 54
   in Microsoft.OData.UriParser.ConvertNode.Accept[T](QueryNodeVisitor`1 visitor) in Microsoft.OData.UriParser\ConvertNode.cs: riga 28
   in Microsoft.AspNetCore.OData.Query.Validator.OrderByModelLimitationsValidator.Visit(SingleValueFunctionCallNode nodeIn) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\OrderByModelLimitationsValidator.cs: riga 142
   in Microsoft.OData.UriParser.SingleValueFunctionCallNode.Accept[T](QueryNodeVisitor`1 visitor) in Microsoft.OData.UriParser\SingleValueFunctionCallNode.cs: riga 55
   in Microsoft.AspNetCore.OData.Query.Validator.OrderByModelLimitationsValidator.TryValidate(OrderByClause orderByClause, Boolean explicitPropertiesDefined) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\OrderByModelLimitationsValidator.cs: riga 47
   in Microsoft.AspNetCore.OData.Query.Validator.OrderByModelLimitationsValidator.TryValidate(IEdmProperty property, IEdmStructuredType structuredType, OrderByClause orderByClause, Boolean explicitPropertiesDefined) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\OrderByModelLimitationsValidator.cs: riga 39
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.ValidateNestedOrderby(OrderByClause orderByClause, SelectExpandValidatorContext validatorContext) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 405
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.ValidateExpandedNavigationSelectItem(ExpandedNavigationSelectItem expandItem, SelectExpandValidatorContext validatorContext) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 200
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.ValidateSelectExpand(SelectExpandClause selectExpandClause, SelectExpandValidatorContext validatorContext) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 92
   in Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\SelectExpandQueryValidator.cs: riga 54
   in Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Query\SelectExpandQueryOption.cs: riga 266
   in Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\Validator\ODataQueryValidator.cs: riga 106
   in Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings) in D:\a\1\s\src\Microsoft.AspNetCore.OData\Query\ODataQueryOptions.cs: riga 652

Reproduce steps
A query like $select=CollectionProperty($orderby=length(Code)) or $expand=CollectionNavigation($orderby=length(Code))

@Xriuk Xriuk added the bug Something isn't working label Dec 13, 2024
@corranrogue9
Copy link
Contributor

The correct syntax for this request is $select=CollectionProperty($orderby=length(code=Code)) (note the parameter name inside of the custom function parameter list). Also note that we have strict parsing logic around spacing (so, do not include spaces around the =).

That said, we need to improve this error message to indicate what the issue actually is, especially since callers will likely want to surface this as a 4xx to let their client know to fix the syntax.

@corranrogue9 corranrogue9 self-assigned this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants