pdevito3/QueryKit

Filtering Guid nullable throws System.ArgumentException

Closed this issue · 3 comments

When filtering Guid nullable field, it throws System.ArgumentException: Method 'System.String ToString()' declared on type 'System.Guid' cannot be called with instance of type 'System.Nullable1[System.Guid]'`.
Environment info:
.NET 8 web api with EF Core

Used query: filter="accountId==\"639940b9-8fee-4df6-6fad-08dc429a430c\"",
where property is: public Guid? AccountId { get; set; }

Stack trace:
System.ArgumentException: Method 'System.String ToString()' declared on type 'System.Guid' cannot be called with instance of type 'System.Nullable`1[System.Guid]' at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method) at QueryKit.FilterParser.<>c__DisplayClass26_0`1.<ComparisonExprParser>b__4(<>f__AnonymousType10`3 temp) at Sprache.Parse.<>c__DisplayClass32_0`2.<Select>b__0(T t) at Sprache.Parse.<>c__DisplayClass26_0`2.<Then>b__1(IResult`1 s) at Sprache.Parse.<>c__DisplayClass36_0`1.<Or>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass26_0`2.<Then>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass26_0`2.<Then>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass31_0`1.<End>b__0(IInput i) at Sprache.ParserExtensions.TryParse[T](Parser`1 parser, String input) at Sprache.ParserExtensions.Parse[T](Parser`1 parser, String input) at QueryKit.FilterParser.ParseFilter[T](String input, IQueryKitConfiguration config) at QueryKit.QueryableExtensions.ApplyQueryKitFilter[TEntity](IQueryable`1 source, String filter, IQueryKitConfiguration config)

Just a note, it's not related to v1.3.2, since it was happening in v.1.3.0, just a different error:
QueryKit.Exceptions.ParsingException: There was a parsing failure, likely due to an invalid comparison or logical operator. You may also be missing double quotes surrounding a string or guid.
---> System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.Nullable1[System.Guid]' and 'System.Guid'. at System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull) at System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method) at QueryKit.Operators.ComparisonOperator.EqualsType.GetExpression[T](Expression left, Expression right, Type dbContextType) at QueryKit.FilterParser.<>c__DisplayClass26_01.b__4(<>f__AnonymousType103 temp) at Sprache.Parse.<>c__DisplayClass32_02.b__0(T t) at Sprache.Parse.<>c__DisplayClass26_02.<Then>b__1(IResult1 s) at Sprache.ResultHelper.IfSuccess[T,U](IResult1 result, Func2 next) at Sprache.Parse.<>c__DisplayClass26_02.<Then>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass36_01.b__0(IInput i) at Sprache.Parse.<>c__DisplayClass26_02.<Then>b__0(IInput i) at Sprache.Parse.<>c__DisplayClass26_02.b__0(IInput i) at Sprache.Parse.<>c__DisplayClass31_01.<End>b__0(IInput i) at Sprache.ParserExtensions.TryParse[T](Parser1 parser, String input) at Sprache.ParserExtensions.Parse[T](Parser1 parser, String input) at QueryKit.FilterParser.ParseFilter[T](String input, IQueryKitConfiguration config) --- End of inner exception stack trace --- at QueryKit.FilterParser.ParseFilter[T](String input, IQueryKitConfiguration config) at QueryKit.QueryableExtensions.ApplyQueryKitFilter[TEntity](IQueryable1 source, String filter, IQueryKitConfiguration config)

Amazing work, thanks for the response :)

Thanks! And appreciate the heads up

FYI, I did notice #37 too while I was in there, just didn't have time to address it last night. Will get to it at some point 👍