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

feat: support pydantic2.0 #1427

Merged
merged 5 commits into from
Jul 21, 2023
Merged

feat: support pydantic2.0 #1427

merged 5 commits into from
Jul 21, 2023

Conversation

long2ice
Copy link
Member

Description

Support pydantic2.0

Motivation and Context

#1419

How Has This Been Tested?

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@long2ice long2ice marked this pull request as draft July 18, 2023 07:55
@long2ice long2ice linked an issue Jul 21, 2023 that may be closed by this pull request
@long2ice long2ice marked this pull request as ready for review July 21, 2023 02:23
@long2ice long2ice merged commit 743843c into develop Jul 21, 2023
0 of 8 checks passed
@long2ice long2ice deleted the pydantic2.0 branch July 21, 2023 02:54
@PeiPeiWow
Copy link

Hi, I am using pydantic2.0, but still have this error, please help!
from app.models import AnyUser, Token, User_Pydantic, Token_Pydantic, UserIn_Pydantic
File "/Users/qilong/Desktop/fastApiUser/app/models.py", line 34, in
User_Pydantic = pydantic_model_creator(AnyUser, name="AnyUser")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/qilong/Desktop/fastApiUser/venv/lib/python3.11/site-packages/tortoise/contrib/pydantic/creator.py", line 437, in pydantic_model_creator
model = cast(Type[PydanticModel], type(_name, (PydanticModel,), properties))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/qilong/Desktop/fastApiUser/venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 95, in new
private_attributes = inspect_namespace(
^^^^^^^^^^^^^^^^^^
File "/Users/qilong/Desktop/fastApiUser/venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 287, in inspect_namespace
and value.module == namespace['module']
~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'module'

@long2ice
Copy link
Member Author

Did you use latest code?

@PeiPeiWow
Copy link

Did you use latest code?

Yes, I used the latest code.
Maybe you have any other ideas?

@PeiPeiWow
Copy link

When I downgraded pydantic==2.0.0, I got this
255324618-57bae3c9-2f77-44b1-bf6f-20b64ff65079

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
fastapi 0.100.0 requires pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,<3.0.0,>=1.7.4, but you have pydantic 2.0 which is incompatible.

so I have to install pydantic==1.10.11, and this solves the problem.

Do you have any other ideas?

@farzbood
Copy link

FastAPI (0.100.0) dependency list shows that it excluded Pydantic (2.0.0, 2.0.1) so first of all using the latest stable version of both frameworks would be a rational choice, which in case of Pydantic it is (2.0.3)
While the maintaners of TortoiseORM are working on finalizing the version bump to support Pydantic V2 ,for clarification of conflicts, you can refer to the list of breaking changes with corresponding migration guides, based on Pydantic official docs.

https://docs.pydantic.dev/latest/migration/#migration-guide
Good Luck

@PeiPeiWow
Copy link

FastAPI (0.100.0) dependency list shows that it excluded Pydantic (2.0.0, 2.0.1) so first of all using the latest stable version of both frameworks would be a rational choice, which in case of Pydantic it is (2.0.3) While the maintaners of TortoiseORM are working on finalizing the version bump to support Pydantic V2 ,for clarification of conflicts, you can refer to the list of breaking changes with corresponding migration guides, based on Pydantic official docs.

https://docs.pydantic.dev/latest/migration/#migration-guide Good Luck

Thank you so much

esrehmki pushed a commit to esrehmki/tortoise-orm that referenced this pull request Aug 17, 2023
* feat: support pydantic2.0

* fix: test

* feat: finish pydantic2.0 support

* ci: fix style

* fix: pydantic warn
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.

Does pydantic contrib support Pydantic V2?
3 participants