Skip to content
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

Allow using Pydantic v2 #533

Merged
merged 5 commits into from
Jul 12, 2023
Merged

Allow using Pydantic v2 #533

merged 5 commits into from
Jul 12, 2023

Conversation

ninoseki
Copy link
Contributor

@ninoseki ninoseki commented Jul 8, 2023

The latest version of FastAPI (v0.100.0) supports Pydantic v2.

I'd like to use redis-om-python with Pydantic v2 while keeping the compatibility.

This PR does:

  • Allow using Pydantic v2 (pydantic = ">=1.10.2,<2.1.0")
  • Add _compat.py file to import proper Pydantic classes, etc.
    • Do from pydantic import ... if Pydantic is v1
    • Do from pydantic.v1 import ... if Pydantic is v2 (Note: Pydantic v2 contains v1 in v1 module)

It allows using Pydantic v2 along with redis-om-python.

@ninoseki
Copy link
Contributor Author

ninoseki commented Jul 8, 2023

There are lint & dependency audit errors.

I'm sure the lint error is out of the scope of this PR.

/home/runner/.local/bin/poetry run mypy ./tests/ aredis_om redis_om --ignore-missing-imports --exclude _compat\.py$
redis_om/model/cli/migrate.py:6: error: Argument 1 has incompatible type "Callable[[Any], Any]"; expected <nothing>
aredis_om/model/cli/migrate.py:6: error: Argument 1 has incompatible type "Callable[[Any], Any]"; expected <nothing>

I'm not sure about the audit error. Could you help me to fix the issue, please? (If this PR looks good)

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 68.42% and project coverage change: -0.33 ⚠️

Comparison is base (70f6401) 78.94% compared to head (099ca96) 78.61%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #533      +/-   ##
==========================================
- Coverage   78.94%   78.61%   -0.33%     
==========================================
  Files          14       15       +1     
  Lines        1178     1188      +10     
==========================================
+ Hits          930      934       +4     
- Misses        248      254       +6     
Flag Coverage Δ
unit 78.61% <68.42%> (-0.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aredis_om/_compat.py 60.00% <60.00%> (ø)
aredis_om/model/encoders.py 50.70% <100.00%> (-0.69%) ⬇️
aredis_om/model/model.py 87.03% <100.00%> (-0.06%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@chayim
Copy link
Contributor

chayim commented Jul 11, 2023

@ninoseki I've merged master in accordingly.

@ninoseki
Copy link
Contributor Author

Thanks and please let me know if I need additional works on this PR.

@chayim
Copy link
Contributor

chayim commented Jul 12, 2023

given the opt in nature - and the pydantic changes.. it seems very clean.

@chayim chayim merged commit 3a0fa0c into redis:main Jul 12, 2023
11 checks passed
@ninoseki ninoseki deleted the pydantic-v2 branch July 12, 2023 11:10
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

Successfully merging this pull request may close these issues.

None yet

3 participants