python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Docs Example loading-from-a-pydantic-settings is wrong

Open mancioshell opened this issue 2 years ago • 0 comments

https://python-dependency-injector.ets-labs.org/providers/configuration.html#loading-from-a-pydantic-settings

In the docs, i have read this:

To get the data from pydantic settings Configuration provider calls Settings.dict() method. If you need to pass an argument to this call, use .from_pydantic() keyword arguments.

class Settings(BaseSettings):

    aws: AwsSettings = AwsSettings()
    optional: str = Field(default="default_value")


class Container(containers.DeclarativeContainer):

    config = providers.Configuration()

container = Container()
container.config.from_pydantic(Settings())
assert container.config.aws.access_key_id() == "KEY"

so container.config is a dict, and cannot access aws attribute.

mancioshell avatar Sep 09 '22 14:09 mancioshell