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

OData Collection requests with $apply (aggregation) still failing when Client/Server side pagination enabled. #918

Closed
kairgrw opened this issue May 12, 2023 · 0 comments · Fixed by #941
Assignees
Labels
bug Something isn't working

Comments

@kairgrw
Copy link

kairgrw commented May 12, 2023

Looks like, it's a long story from issue #420 which appears to be partially fixed but still not working for Client/Server side pagination enabled.

Our project settings:

  • Framework: .NET 7.0
  • EF Core: 7.0
  • Language: C# 11.0
  • Microsoft.AspNetCore.OData: 8.0.12 (doesn't matter, still is not working since 8.0.5)

It's reproducible on ODataRoutingSample: ASP.NET Core OData sample project.

Requests:

  1. Orders: http://localhost:5000/v21/Orders
  2. Orders with just $apply (filter + aggregate): http://localhost:5000/v21/Orders?$apply=filter((contains(title,'i')))/aggregate(id with countdistinct as f0)
  3. Orders with $apply (filter + groupBy + aggregate) and $top: http://localhost:5000/v21/Orders?$apply=filter((contains(title,'i')))/groupby((title),aggregate(id with countdistinct as f0))&$top=5
  4. Orders with $apply (filter + aggregate) and $top: http://localhost:5000/v21/Orders?$apply=filter((contains(title,'i')))/aggregate(id with countdistinct as f0)&$top=5

Request 1 works as expected:

{"@odata.context":"http://localhost:5000/v21/$metadata#Orders","value":[{"Id":1,"Title":"Goods"},{"Id":2,"Title":"Magazine"},{"Id":3,"Title":"Fiction"}]}

Request 2 works as expected:

{"@odata.context":"http://localhost:5000/v21/$metadata#Orders(f0)","value":[{"@odata.id":null,"f0":2}]}

Request 3 works as expected:

{"@odata.context":"http://localhost:5000/v21/$metadata#Orders(Title,f0)","value":[{"@odata.id":null,"Title":"Fiction","f0":1},{"@odata.id":null,"Title":"Magazine","f0":1}]}

Request 4 fails with error:

{"error":{"code":"","message":"The query specified in the URI is not valid. The given model does not contain the type 'Microsoft.AspNetCore.OData.Query.Wrapper.NoGroupByAggregationWrapper'.","details":[],"innererror":{"message":"The given model does not contain the type 'Microsoft.AspNetCore.OData.Query.Wrapper.NoGroupByAggregationWrapper'.","type":"Microsoft.OData.ODataException","stacktrace":"   at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinderContext..ctor(IEdmModel model, ODataQuerySettings querySettings, Type clrType) in C:\\Users\\andrey.kliuiko\\Downloads\\AspNetCoreOData-8.0.12\\src\\Microsoft.AspNetCore.OData\\Query\\Expressions\\QueryBinderContext.cs:line 60\r\n   at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.ApplyToCore(IQueryable query, ODataQuerySettings querySettings) in C:\\Users\\andrey.kliuiko\\Downloads\\AspNetCoreOData-8.0.12\\src\\Microsoft.AspNetCore.OData\\Query\\Query\\OrderByQueryOption.cs:line 253\r\n   at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings) in C:\\Users\\andrey.kliuiko\\Downloads\\AspNetCoreOData-8.0.12\\src\\Microsoft.AspNetCore.OData\\Query\\Query\\OrderByQueryOption.cs:line 216\r\n   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings) in C:\\Users\\andrey.kliuiko\\Downloads\\AspNetCoreOData-8.0.12\\src\\Microsoft.AspNetCore.OData\\Query\\ODataQueryOptions.cs:line 429\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions) in C:\\Users\\andrey.kliuiko\\Downloads\\AspNetCoreOData-8.0.12\\src\\Microsoft.AspNetCore.OData\\Query\\EnableQueryAttribute.cs:line 510\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request) in C:\\Users\\andrey.kliuiko\\Downloads\\AspNetCoreOData-8.0.12\\src\\Microsoft.AspNetCore.OData\\Query\\EnableQueryAttribute.cs:line 473\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext, Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request) in C:\\Users\\andrey.kliuiko\\Downloads\\AspNetCoreOData-8.0.12\\src\\Microsoft.AspNetCore.OData\\Query\\EnableQueryAttribute.cs:line 308"}}}

Note that such error can be caught when either Server pagination is enabled [EnableQuery(PageSize = 5)] or Client one is used by sending $top=5 in Request Query parameters.
Seems like, OrderBy option is set by default when Stable sort is enabled and above parameters are used.
Issue #420 may fix the groupBy queries, but no groupBy ones still don't work.

There're quite many queries with such options used in our project, so this bug is very frustrating.
Downgrading to 8.0.4 and below IS NOT AN OPTION.

Looking forward for advice.

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

Successfully merging a pull request may close this issue.

2 participants