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

Configuration is evaluated on container declaration when using Container provider

Open Qjammer opened this issue 3 years ago • 0 comments

Configuration provider will throw ValueError: Missing required environment variable "MYENV" when declaring a container that uses another container as a dependency. The following snippet exemplifies the behavior:

# test.yaml
a: "${MYENV}"
# main.py
class A(containers.DeclarativeContainer):
    config = providers.Configuration(strict=True, yaml_files=["./test.yaml"])

# Commenting out these two lines does not throw
class B(containers.DeclarativeContainer):
    a = providers.Container(A) # Throws ValueError: Missing required environment variable "MYENV"

# Anything after this does not matter.

Expected behavior: The script doesn't throw an exception until the container is instantiated.

Qjammer avatar Sep 01 '22 15:09 Qjammer