Search code examples
pythonfastapipydantic

Strange warning for ValidationError in Pydantic V2


I updated my FastAPI to Pydantic 2.5.2 and I suddenly get the following warning in the logs.

/usr/local/lib/python3.12/site-packages/pydantic/_migration.py:283: UserWarning: `pydantic.error_wrappers:ValidationError` has been moved to `pydantic:ValidationError`.
warnings.warn(f'`{import_path}` has been moved to `{new_location}`.')

Is that problematic and do you know how to fix it?


Solution

  • Just use from from pydantic import ValidationError instead of from pydantic.error_wrappers import ValidationError.

    Now your code works correctly and it's just warning, but in the future versions of Pydantic it will cause the import error.

    If you don't import ValidationError in your code, it probably does one of the libraries you use. In this case just ignore this warning.