BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
2.05k stars 217 forks source link

[BUG] Unable to use Or() in Doc.find_one() - unhashable type 'Eq' #563

Closed omars44 closed 1 year ago

omars44 commented 1 year ago

Describe the bug I'm trying to follow the Or class example, which is:

https://beanie-odm.dev/api-documentation/operators/find/#or

Example:

class Product(Document):
    price: float
    category: str

Or({Product.price<10}, {Product.category=="Sweets"})

And I end up with an unhashable type error, any ideas, what is wrong, my guess is that it's not documented properly. I can contribute if needed to the docs, if I know how to solve this

To Reproduce

class User(Document):
    id: UUID = Field(default_factory=uuid4, primary_key=True)
    email: EmailStr = Field(str)
    password: str = Field(..., min_length=8, description="The user's hashed password")
    username: str = Field(str, min_length=3, max_length=255, description="The user's unique username")
username = 'xyxy'
email = 'xyxy@example.com'    
print(Or({User.email==email}, {User.username==username}), flush=True)

Out:

api  |     print(Or({User.email==email}, {User.username==username}), flush=True)
api  |              ^^^^^^^^^^^^^^^^^^^
api  | TypeError: unhashable type: 'Eq'

Expected behavior A clear and concise description of what you expected to happen. prints the OR query

roman-right commented 1 year ago

Hi @morning-sunn ,

It is a typo in the documentation. I'll fix it asap.

Try this: print(Or(User.email==email, User.username==username), flush=True)