Open arianamiri opened 8 months ago
I created PR covering this issue.
A work around that I used for this would be:
config = providers.Configuration()
json_config = Settings().model_dump(mode='json')
config.from_dict(json_config)
The same issue
Temporary solved with:
config = providers.Configuration()
config.from_dict(AppSecrets().dict())
FYI for anyone else who lands here: @cdonate's workaround is compatible with Pydantic v2.
While @pow3rpi's workaround is technically compatible with Pydantic v2, the .dict()
and .json()
model serialization methods are marked as deprecated in v2 and will eventually be removed in favor of .model_dump()
and .model_dump_json()
.
@bmcandr Good point! Thanks.
In pydantic 2.0+ the
BaseSettings
class has been moved into a optional package, pydantic-settings. The configuration provider'sfrom_pydantic
method expect to find it in the pydantic package:https://github.com/ets-labs/python-dependency-injector/blob/master/src/dependency_injector/providers.pyx#L1806-L1816
This results in an error like:
Furthermore, the
BaseModel.dict
method used in the last line of this method is deprecated and has been replaced byBaseModel.model_dump
. The method still exists but emits deprecation warnings when accessed.