Skip to content

Compatibility Issue with Pydantic 2 #726

Closed
@Pentusha

Description

@Pentusha

The major version of Pydantic was recently released and lost backward compatibility. In particular, the .from_pydantic method stopped working for providers.Configuration due to the fact that the BaseSettings class now needs to be imported from a new package called pydantic-settings.

[tool.poetry.dependencies]
python = "^3.11"
pydantic = "^2.0.3"
pydantic-settings = "^2.0.2"
Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 112, in _get_module_details
  File "/home/pentusha/projects/kyt.service-template/app/__init__.py", line 4, in <module>
    from app.core.containers import app_container
  File "/home/pentusha/projects/kyt.service-template/app/core/containers.py", line 80, in <module>
    app_container = AppContainer()
                    ^^^^^^^^^^^^^^
  File "src/dependency_injector/containers.pyx", line 742, in dependency_injector.containers.DeclarativeContainer.__new__
  File "src/dependency_injector/containers.pyx", line 393, in dependency_injector.containers.DynamicContainer.load_config
  File "src/dependency_injector/providers.pyx", line 2106, in dependency_injector.providers.Configuration.load
  File "src/dependency_injector/providers.pyx", line 2381, in dependency_injector.providers.Configuration.from_pydantic
  File "/home/pentusha/.cache/pypoetry/virtualenvs/kyt-service-template-cl7ERtKI-py3.11/lib/python3.11/site-packages/pydantic/__init__.py", line 207, in __getattr__
    return _getattr_migration(attr_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentusha/.cache/pypoetry/virtualenvs/kyt-service-template-cl7ERtKI-py3.11/lib/python3.11/site-packages/pydantic/_migration.py", line 288, in wrapper
    raise PydanticImportError(
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.0.3/migration/#basesettings-has-moved-to-pydantic-settings for more details.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions