Skip to content

[Bug 🐞] Pydantic EmailStr Fields fail to work with redis-om find queries #700

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

Open
XChikuX opened this issue May 17, 2025 · 1 comment

Comments

@XChikuX
Copy link

XChikuX commented May 17, 2025

from redis_om import HashModel, Field
from pydantic import EmailStr, ConfigDict

class Email(HashModel):
    email: EmailStr = Field(
        index=True, title="Email", description="Enter your email address."
    )

    class Meta:
        database = redis_conn

    model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)

    @classmethod
    async def migrate(cls):
        await Migrator().run()

The above definition fails when used for a query:

await Email.find(Email.email == email).first()

Gives:

 File "/root/code/backend/app/query.py", line 174, in login                                                                                                                        
   user = await RedisUser.find(RedisUser.email == email).first()                                                                                                                   
                                       ^^^^^^^^^^^^^^^                                                                                                                                     
    File "/root/code/backend/.env/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 271, in __getattr__                                                   
   raise AttributeError(item)                                                                                                                                                      
    AttributeError: email     

redis-om version: v1.0.2-beta
pydantic: v2

@XChikuX
Copy link
Author

XChikuX commented May 17, 2025

This used to work with pydantic v1 with redis-om v0.3.3
@abrookins #691

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