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

Fix usage of pydantic v1 #3715

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jonringer
Copy link

@jonringer jonringer commented Feb 6, 2025

Issue #, if available

#3617
Supercedes: #3710

Description of changes

Importing error_wrappers or ValidationError using python's import syntax works as expected as it can also traverse directories and files. However, doing something like from pydantic import v1 as pydantic actually just reads pydantic/v1/__init__.py which just re-exports pydantic namespace (for 1.10.17+) but it DOES NOT re-export error_wrappers, however it does re-export ValidationError which is what we care about.

Description of how you validated changes

Ran test suite with pydantic2, and able to import files with pydantic1

Checklist

Examples?

import example:

$ python
Python 3.11.10 (main, Sep  7 2024, 01:03:31) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydantic
>>> pydantic.__version__
'1.10.21'
>>> pydantic.v1.error_wrappers
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pydantic' has no attribute 'v1'
>>> import pydantic.v1 as p
>>> p
<module 'pydantic.v1' from '/nix/store/fyn8cs661n9mbldsn0w3pb29pf62rprn-python3.11-pydantic-1.10.21/lib/python3.11/site-packages/pydantic/v1/__init__.py'>
>>> p.error_wrappers
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pydantic.v1' has no attribute 'error_wrappers'
>>> p.ValidationError(
... 
KeyboardInterrupt
>>> p.ValidationError
<class 'pydantic.error_wrappers.ValidationError'>
>>> from pydantic.v1 import error_wrappers
>>> error_wrappers
<module 'pydantic.v1.error_wrappers' from '/nix/store/fyn8cs661n9mbldsn0w3pb29pf62rprn-python3.11-pydantic-1.10.21/lib/python3.11/site-packages/pydantic/v1/error_wrappers.py'>
>>> error_wrappers.ValidationError
<class 'pydantic.error_wrappers.ValidationError'>

@jonringer jonringer requested a review from a team as a code owner February 6, 2025 22:03
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.

1 participant