Skip to content

Error on filtering by indexed nullable DateTime #514

@ALDamico

Description

@ALDamico

I'm storing JSON documents in my Redis instance where one of the fields is a Nullable marked with an Indexable attribute.

Inserting and updating the model works flawlessly, however, if I attempt to filter the IRedisCollection where all these properties are null, I get a NullReferenceException:

   at Redis.OM.Common.ExpressionParserUtilities.ValueToString(Object value)
   at Redis.OM.Common.ExpressionParserUtilities.GetOperandStringForQueryArgs(Expression exp, List`1 parameters, Boolean treatEnumsAsInt, Boolean negate, Boolean treatBooleanMemberAsUnary)
   at Redis.OM.Common.ExpressionTranslator.TranslateBinaryExpression(BinaryExpression binExpression, List`1 parameters)
   at Redis.OM.Common.ExpressionTranslator.BuildQueryFromExpression(Expression exp, List`1 parameters)
   at Redis.OM.Common.ExpressionTranslator.TranslateWhereMethod(MethodCallExpression expression, List`1 parameters)
   at Redis.OM.Common.ExpressionTranslator.BuildQueryFromExpression(Expression expression, Type type, Expression mainBooleanExpression, Type rootType)
   at Redis.OM.Searching.RedisCollectionEnumerator`1..ctor(Expression exp, IRedisConnection connection, Int32 chunkSize, RedisCollectionStateManager stateManager, Expression`1 booleanExpression, Boolean saveState, Type rootType, Type type)
   at Redis.OM.Searching.RedisCollection`1.GetAsyncEnumerator(CancellationToken cancellationToken)
   at Redis.OM.Searching.RedisCollection`1.ToListAsync()
   at RedisOmNestedObject.Program.Main(String[] args) in C:\Users\Luciano Damico\RiderProjects\RedisOmNestedObject\RedisOmNestedObject\Program.cs:line 31
   at RedisOmNestedObject.Program.<Main>(String[] args)

From what I've been able to grok, it looks like the library doesn't create these keys if the value is null, but when the .Where() LINQ method is called, it takes their existence for granted and the ValueToString method throws an exception because it calls the GetType method on a null value.

I'm not sure this is a bug, or I'm simply using Redis wrong (may well be!).

As a workaround, materializing the query to a list and then filtering by null values works, but it feels like a very hacky solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions