odata.net
odata.net copied to clipboard
UriParser throws NullReferenceException when trying to filter by unknown property
The OData.UriParser throws NullReferenceException when passing a filter which references an unknown collection property.
Assemblies affected
Microsoft.OData.Core 7.6.0
Reproduce steps
Define entity with a collection property and try to filter on a non-existent property.
class Entity {
IEnumerable<SubEntity> Children { get; }
}
class SubEntity {
string Id { get; set; }
}
Try to query the entity with a bad filter:
$filter=Children/SomeProperty eq '234'
I know that the filter should use any() or other collection filter function - but the UriParser should not throw NullReferenceException in any case.
Expected result
ODataException with appropriate message should be thrown.
Actual result
Exception is thrown:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.OData.UriParser.EndPathBinder.BindEndPath(EndPathToken endPathToken)
at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
at Microsoft.OData.UriParser.BinaryOperatorBinder.GetOperandFromToken(BinaryOperatorKind operatorKind, QueryToken queryToken)
at Microsoft.OData.UriParser.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()
at Microsoft.AspNet.OData.Query.FilterQueryOption.get_FilterClause()
at Microsoft.AspNet.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)
at Microsoft.AspNet.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)
...
@KanishManuja-MS Any chance this will get fixed at some time ? Returning HTTP 500 from our API for invalid queries is quite unusual.
Our team is facing this issue as well. I hope this issue gets prioritised 😕
@corranrogue9 Maybe you could help on this issue ? I saw you are active in this repo.