You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assemblies affected
Microsoft.AspNetCore.OData version 8.2.5
Describe the bug
According to OASIS docs, system query options must support case-insensitive system query option names with or without a $ prefix.
When using AutoExpand or AutoSelect, and specifying a matching system query option that's not lower case (such as $Expand) an exception is thrown. The exception indicates that Expand is being added twice.
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. Query option '$expand/expand' was specified more than once, but it must be specified at most once.",
"details": [],
"innererror": {
"message": "Query option '$expand/expand' was specified more than once, but it must be specified at most once.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " at Microsoft.OData.UriParser.ODataQueryOptionParser.TryGetQueryOption(String name, String& value)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()\r\n at Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.ProcessLevels()\r\n at Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.get_ProcessedSelectExpandClause()\r\n at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplySelectExpand[T](T entity, ODataQuerySettings querySettings)\r\n at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext, Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)"
}
}
}
I have managed to track the error to the function AddAutoSelectExpandProperties within Microsoft.AspNetCore.Odata.Query.OdataQueryOptions.cs.
The line below explicitly adds the auto expanded path values to the queryParameters dictionary with the key "$expand", in the case that the query parameters are also in lower case, this works, but if the query parameters are "$Expand", for example, instead of overriding the parameter a second queryParameter is added.
queryParameters["$expand"]=autoExpandRawValue;
The simple solution may be to ensure that the query parameter is always in lower case...
privateIDictionary<string,string>GetODataQueryParameters(){Dictionary<string,string>result=newDictionary<string,string>();foreach(var query in Request.Query){stringkey= query.Key.Trim().ToLower();stringvalue= query.Value.ToString();// code removed for brevity
...}returnresult;}
Expected behavior
This shouldn't error and case on the Expand or Select query parameters should not matter.
The text was updated successfully, but these errors were encountered:
@timClyburn Could you provide the sample example of AutoSelect that is failing and share the error message.
I am able to reproduce this issue for AutoExpand but not for AutoSelect
@timClyburn Could you provide the sample example of AutoSelect that is failing and share the error message. I am able to reproduce this issue for AutoExpand but not for AutoSelect
@WanjohiSammy I don't have an example for the AutoSelect, the issue was identified when using AutoExpand, but since they both shared the same function for generating the query I included both.
@WanjohiSammy I don't have an example for the AutoSelect, the issue was identified when using AutoExpand, but since they both shared the same function for generating the query I included both.
@timClyburn Is it okay to update the title to something like this: AutoExpand not working correctly with $Expand uri query parameters
timClyburn
changed the title
AutoExpand and AutoSelect not working correctly with $Expand and $Select uri query parameters
AutoExpand not working correctly with $Expand uri query parameters
Sep 4, 2024
Assemblies affected
Microsoft.AspNetCore.OData version 8.2.5
Describe the bug
According to OASIS docs, system query options must support case-insensitive system query option names with or without a $ prefix.
When using AutoExpand or AutoSelect, and specifying a matching system query option that's not lower case (such as $Expand) an exception is thrown. The exception indicates that Expand is being added twice.
I have managed to track the error to the function
AddAutoSelectExpandProperties
withinMicrosoft.AspNetCore.Odata.Query.OdataQueryOptions.cs
.The line below explicitly adds the auto expanded path values to the queryParameters dictionary with the key "$expand", in the case that the query parameters are also in lower case, this works, but if the query parameters are "$Expand", for example, instead of overriding the parameter a second queryParameter is added.
The simple solution may be to ensure that the query parameter is always in lower case...
Expected behavior
This shouldn't error and case on the Expand or Select query parameters should not matter.
The text was updated successfully, but these errors were encountered: