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

Filter with enum integer value #2542

Closed
cheng93 opened this issue Oct 26, 2022 · 1 comment · Fixed by #3014
Closed

Filter with enum integer value #2542

cheng93 opened this issue Oct 26, 2022 · 1 comment · Fixed by #3014

Comments

@cheng93
Copy link
Contributor

cheng93 commented Oct 26, 2022

Short summary (3-5 sentences) describing the issue.

Filtering an enum with it's integer value causes an exception

Assemblies affected

Which assemblies and versions are known to be affected e.g. OData .Net lib 7.x

Microsoft.AspNetCore.OData 8.0.11
Also whatever the Tripin service on odata.org is using

Reproduce steps

The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.

the Tripin service used on odata.org is using this library, as the error message is the same.

https://services.odata.org/TripPinRESTierService/(S(bhxqknjf3hgdlqxrtt5uuffr))/People?$count=true&$filter=Gender%20eq%201

Expected result

What would happen if there wasn't a bug.

Same results as https://services.odata.org/TripPinRESTierService/(S(bhxqknjf3hgdlqxrtt5uuffr))/People?$count=true&$filter=Gender%20eq%20%27Female%27

Actual result

What is actually happening.

{"error":{"code":"","message":"A binary operator with incompatible types was detected. Found operand types 'Trippin.PersonGender' and 'Edm.Int32' for operator kind 'Equal'."}}
{"stacktrace": "   at Microsoft.OData.UriParser.BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right, TypeFacetsPromotionRules facetsPromotionRules)\r\n   at Microsoft.OData.UriParser.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n   at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)\r\n   at Microsoft.OData.UriParser.BinaryOperatorBinder.GetOperandFromToken(BinaryOperatorKind operatorKind, QueryToken queryToken)\r\n   at Microsoft.OData.UriParser.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n   at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)\r\n   at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()\r\n   at Microsoft.AspNetCore.OData.Query.FilterQueryOption.get_FilterClause()\r\n   at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n   at Microsoft.AspNetCore.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n   at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)"}

Additional detail

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

enum  = [ qualifiedEnumTypeName ] SQUOTE enumValue SQUOTE
enumValue  = singleEnumValue
singleEnumValue = enumerationMember / enumMemberValue
enumMemberValue = int64Value

which I assume means we should able to use a long when referring to an enum

@cheng93
Copy link
Contributor Author

cheng93 commented Oct 26, 2022

Alternatively if we consider

enum = SQUOTE enumMemberValue SQUOTE

https://services.odata.org/TripPinRESTierService/(S(bhxqknjf3hgdlqxrtt5uuffr))/People?$count=true&$filter=Gender%20eq%20%271%27

We get

{"error":{"code":"","message":"The string '1' is not a valid enumeration type constant."}}

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

Successfully merging a pull request may close this issue.

2 participants