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

Issue with $compute and $select on Array Properties in OData Query #3063

Open
xuzhg opened this issue Sep 16, 2024 · 1 comment
Open

Issue with $compute and $select on Array Properties in OData Query #3063

xuzhg opened this issue Sep 16, 2024 · 1 comment
Labels

Comments

@xuzhg
Copy link
Member

xuzhg commented Sep 16, 2024

I'm working with OData and I've encountered an issue when using the $compute and $select query options with properties of type array. Here's what I'm trying to achieve:

Query URL for Non-Array Property (Working):

http://host/odata/MyEntity?$compute=int as myint,string as mystring &$select=myint,mystring
This URL works as expected. It returns the myint and mystring properties in the response, replacing the original entity properties int and string.

Query URL for Array Property (Not Working):

http://host/odata/MyEntity?$compute=array as myarray&$select=myarray
This URL results in an error. I want to transform the array property into myarray in the response, similar to how it works with non-array properties.

Error Details:
I am receiving the following error when attempting the second query:

Error Message:

"Message": "Object reference not set to an instance of an object."
Stack Trace:

   at Microsoft.OData.UriParser.ComputeBinder.BindComputeExpressionToken(ComputeExpressionToken token)
   at Microsoft.OData.UriParser.ComputeBinder.BindCompute(ComputeToken token)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseComputeImplementation(String compute, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseCompute()
   at Microsoft.AspNetCore.OData.Query.ComputeQueryOption.get_ComputeClause()
   at Microsoft.AspNetCore.OData.Query.Validator.ComputeQueryValidator.Validate(ComputeQueryOption computeQueryOption, ODataValidationSettings validationSettings)
   at Microsoft.AspNetCore.OData.Query.ComputeQueryOption.Validate(ODataValidationSettings validationSettings)
   at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)
   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)
   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)
   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)
   at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---\n
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter()
--- End of stack trace from previous location ---\n
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---\n
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext cont...

Ported from Stackoverflow at here.

@xuzhg
Copy link
Member Author

xuzhg commented Sep 16, 2024

I cannot understand why the compute expression should be single value node at here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants