-
Notifications
You must be signed in to change notification settings - Fork 121
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
Indexing boolean fields breaks something #510
Comments
I can confirm this as well, that the JSONModel doesn't support indexing boolean fields. Here is my testcase that shows the same thing: """This file demonstrates that redis_om_python cannot index/search boolean fields"""
from redis_om import Field, JsonModel, Migrator
class MyObjectBroken(JsonModel):
my_string: str = Field(index=True)
my_int: int = Field(index=True)
my_bool: bool = Field(index=True)
class MyObjectWorks(JsonModel):
my_string: str = Field(index=True)
my_int: int = Field(index=True)
Migrator().run()
# Add some objects that are broken
object1 = MyObjectBroken(my_string="", my_int=1, my_bool=False)
object1.save()
object2 = MyObjectBroken(my_string="", my_int=1, my_bool=False)
object2.save()
# Add some objects that work
object3 = MyObjectWorks(my_string="", my_int=1)
object3.save()
object4 = MyObjectWorks(my_string="", my_int=1)
object4.save()
objects = MyObjectBroken.find().all()
print(f"Found {len(objects)} MyObjectBroken expected 2")
object_get = MyObjectBroken.get(object1.pk)
print(f"Found {object_get=} MyObjectBroken")
objects = MyObjectWorks.find().all()
print(f"Found {len(objects)} MyObjectWorks expected 2")
object_get = MyObjectWorks.get(object3.pk)
print(f"Found {object_get=} MyObjectWorks") If you run this, you'll get the following output showing the object with a boolean field doesn't work:
|
See #193 for where it's defined that booleans aren't supported yet, but seem to be supported at some point? |
From my sleuthing, since the
This is coming from this line: redis-om-python/aredis_om/model/model.py Line 1890 in d1f6959
From the docs of |
I found a workaround for this issue. Since the Here is the code that I tested on redis-om 0.1.3: """This file demonstrates that redis_om_python cannot index/search boolean fields"""
from redis_om import Field, JsonModel, Migrator
class MyObjectBroken(JsonModel):
my_string: str = Field(index=True)
my_int: int = Field(index=True)
my_bool: int = Field(index=True) # declare as int, but pass in boolean values works
class MyObjectWorks(JsonModel):
my_string: str = Field(index=True)
my_int: int = Field(index=True)
Migrator().run()
# Add some objects that are broken
object1 = MyObjectBroken(my_string="", my_int=1, my_bool=False)
object1.save()
object2 = MyObjectBroken(my_string="", my_int=1, my_bool=True)
object2.save()
# Add some objects that work
object3 = MyObjectWorks(my_string="", my_int=1)
object3.save()
object4 = MyObjectWorks(my_string="", my_int=1)
object4.save()
objects = MyObjectBroken.find().all()
print(f"Found {len(objects)} MyObjectBroken expected 2")
objects = MyObjectBroken.find(MyObjectBroken.my_bool == int(False)).all()
print(f"Found {len(objects)} MyObjectBroken with bool as False expected 1")
object_get = MyObjectBroken.get(object1.pk)
print(f"Found {object_get=} MyObjectBroken")
objects = MyObjectWorks.find().all()
print(f"Found {len(objects)} MyObjectWorks expected 2")
object_get = MyObjectWorks.get(object3.pk)
print(f"Found {object_get=} MyObjectWorks") Here is the output from it:
|
result:
executing a basic get by pk works fine.
result:
when running find().all(), the result is empty:
If I set the bool value to Index=False, the indexing starts working fine:
The text was updated successfully, but these errors were encountered: