redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.13k stars 114 forks source link

decimal.Decimal breaks JsonModel.find() #654

Open zidokobik opened 2 months ago

zidokobik commented 2 months ago

Consider the following code:

import asyncio
from decimal import Decimal
from aredis_om import JsonModel, Field, Migrator

class Book(JsonModel):
    author : str = Field(index=True)
    pages : Decimal = Field(index=True, default=Decimal('0'))

async def main():
    await Migrator().run()

    author = 'example@example.com'
    book = Book(author=author)
    await book.save()

    query = await Book.find(Book.author == author).all()
    print(query)  # []

if __name__ == "__main__":
    with asyncio.Runner() as runner:
        runner.run(main())

query should not be empty.

Version: redis==4.6.0 redis-om==0.3.2 pydantic==2.8.2

Removing the Decimal field works as normal, so as using HashModel. Is this a bug ?