redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.11k stars 110 forks source link

Make RedisModel compatible with Pydantic 2.x #626

Closed arareko closed 2 months ago

arareko commented 4 months ago

This updates RedisModel to use model_config with the right parameters (e.g. from_attributes) instead of the Config class with deprecated attributes (e.g. orm_mode) when Pydantic 2.x is installed. It will most likely resolve the warning shown in #612, but not the main issue reported there.

UserWarning: Valid config keys have changed in V2: * 'orm_mode' has been renamed to 'from_attributes'

I found the above warning while running a FastAPI app in uvicorn within a Python 3.12 virtualenv and the following packages:

annotated-types==0.7.0
anyio==4.4.0
certifi==2024.2.2
cffi==1.16.0
click==8.1.7
cryptography==42.0.7
dnspython==2.6.1
email_validator==2.1.1
fastapi==0.111.0
fastapi-cli==0.0.4
h11==0.14.0
hiredis==2.3.2
httpcore==1.0.5
httptools==0.6.1
httpx==0.27.0
idna==3.7
Jinja2==3.1.4
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
more-itertools==10.2.0
orjson==3.10.3
pycparser==2.22
pydantic==2.7.2
pydantic_core==2.18.3
Pygments==2.18.0
python-dotenv==1.0.1
python-multipart==0.0.9
python-ulid==1.1.0
PyYAML==6.0.1
redis==5.0.4
redis-om==0.3.1
rich==13.7.1
setuptools==69.5.1
shellingham==1.5.4
sniffio==1.3.1
starlette==0.37.2
typer==0.12.3
types-cffi==1.16.0.20240331
types-pyOpenSSL==24.1.0.20240425
types-redis==4.6.0.20240425
types-setuptools==70.0.0.20240524
typing_extensions==4.12.0
ujson==5.10.0
uvicorn==0.30.0
uvloop==0.19.0
watchfiles==0.22.0
websockets==12.0

This also fixes a few warnings/issues I encountered while testing my changes with make format/lint/test.

arareko commented 3 months ago

@slorello89 Can you have a look at this? Thanks!

Souhib commented 3 months ago

Looking forward for this pull request to be merged ! šŸ‘€ Thanks @arareko ! Would be really nice from you @slorello89 if you can merge it if you think everything is good from your side ! šŸ™

arareko commented 2 months ago

@slorello89 Any chance you can have a look at this?

slorello89 commented 2 months ago

LGTM šŸ‘ thanks for submitting @arareko

XChikuX commented 2 months ago

Can we get a new version on pypi with these changes? @slorello89