redis / redis-om-python

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

Use case in README error in EmailStr #592

Closed EiffelQ closed 3 months ago

EiffelQ commented 4 months ago

Use case in README is following. ` import datetime from typing import Optional

from pydantic import EmailStr, ValidationError

from redis_om import HashModel

class Customer(HashModel): first_name: str last_name: str email: EmailStr join_date: datetime.date age: int bio: Optional[str]

andrew = Customer( first_name="Andrew", last_name="Brookins", email="andrew.brookins@example.com", join_date=datetime.date.today(), age=38, bio="Python developer, works at Redis, Inc." ) `

It'll response error ValidationError: 1 validation error for Customer email instance of EmailStr expected (type=type_error.arbitrary_type; expected_arbitrary_type=EmailStr)

slorello89 commented 3 months ago

So the issue here is that when we, added Pydantic 2.0 support, we really only allowed users to allow Redis OM Python to co-exist with pydantic 2.0 rather than actually supporting it properly, consequentially, if you are using the old examples, you need to import things like EmailStr from pydantic.v1 rather than pydantic. I've updated the README to reflect this reality.