redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.07k stars 108 forks source link

FindQuery.resolve_value can't resolve for Operations.IN and RedisSearchFieldTypes.NUMERIC #499

Open landeholt opened 1 year ago

landeholt commented 1 year ago

I believe I've found a miss in the resolver.

Currently, I can't seem to do the following when a field is numeric:


class MyModel(JSONModel):
    my_field: int = Field(index=True)

MyModel(my_field=1).save()

assert MyModel.find(MyModel.my_field << [1,2,3,4]).all() == []

It does work when my_field is a string, but I expect it to work for numerics as well.

I've experimented and added the following code:

elif op is Operators.IN:
    result += "|".join(map(lambda v: f"(@{field_name}: [{v} {v}])", value))

to https://github.com/redis/redis-om-python/blob/4ee61cb8b9b4097894df79b34bd32efb82b9fc00/aredis_om/model/model.py#L545-L557

I'm quite concerned about the performance of chaining multiple OR expressions, but this is the only way I've found and seen others doing.