Skip to content

'in' operator can't be used with open property #1958

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

Closed
cppcraze opened this issue Dec 16, 2020 · 2 comments
Closed

'in' operator can't be used with open property #1958

cppcraze opened this issue Dec 16, 2020 · 2 comments

Comments

@cppcraze
Copy link

'in' operator can't be used with open property

Assemblies affected

Microsoft.OData.Core 7.7.3

Reproduce steps

Request with below $filter will fail
$filter=extension_2782bd535fad492abfcc5ac40ae3a14b_teststring in ('a', 'b')

Expected result

This $filter expression should be correctly parsed with open property as left operand and an array of string as right operand.

Actual result

It hit NullReferenceException at

at Microsoft.OData.Edm.EdmUtil.CheckArgumentNull[T](T value, String parameterName)
at Microsoft.OData.Edm.EdmCollectionType..ctor(IEdmTypeReference elementType)
at Microsoft.OData.UriParser.InBinder.BindInOperator(InToken inToken, BindingState state)
at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()

Additional detail

It is because of below left.TypeReference is null if left is SingleValueOpenPropertyAccessNode.

SingleValueNode left = this.GetSingleValueOperandFromToken(inToken.Left);
CollectionNode right = this.GetCollectionOperandFromToken(
    inToken.Right, new EdmCollectionTypeReference(new EdmCollectionType(left.TypeReference)), state.Model);

File: https://github.com/OData/odata.net/blob/master/src/Microsoft.OData.Core/UriParser/Binders/InBinder.cs
Line: 48

@mikepizzo
Copy link
Member

We can look at supporting this better (at least not returning a nullref exception), but in the meantime you should be able to do an explicit cast of the open property to make this work:

$filter=cast(extension_2782bd535fad492abfcc5ac40ae3a14b_teststring, Edm.String) in ('a', 'b')

@gathogojr
Copy link
Contributor

Fixed by #3190

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

No branches or pull requests

3 participants