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

Error on filtering by indexed nullable DateTime #514

Open
ALDamico opened this issue Jan 28, 2025 · 0 comments
Open

Error on filtering by indexed nullable DateTime #514

ALDamico opened this issue Jan 28, 2025 · 0 comments

Comments

@ALDamico
Copy link

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.

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

1 participant