Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicContainer injected at least two levels deep throws AttributeError #841

Open
vlad-ghita opened this issue Dec 14, 2024 · 0 comments
Open

Comments

@vlad-ghita
Copy link
Contributor

Hey @rmk135

Thank you for a great project!

Your example works perfect for DeclarativeContainers.

However, I'm using a DynamicContainer at the lowest level.

This seems to cause confusion.

from dependency_injector import containers, providers


class C1(containers.DeclarativeContainer):
    deps = providers.DependenciesContainer()


class C2(containers.DeclarativeContainer):
    c1 = providers.DependenciesContainer()
    foo = c1.deps.foo


deps = containers.DynamicContainer()
deps.foo = providers.Object("foo")

c2 = C2(c1=C1(deps=deps))

assert "foo" == c2.foo()

Outputs:

Traceback (most recent call last):
  File "test2.py", line 8, in <module>
    class C2(containers.DeclarativeContainer):
  File "test2.py", line 10, in C2
    foo = c1.deps.foo
          ^^^^^^^^^^^
  File "src/dependency_injector/providers.pyx", line 847, in dependency_injector.providers.Dependency.__getattr__
AttributeError: Provider "Dependency" has no attribute "foo"

Could you, please, advise on how to achieve this?

I noticed a similar issue when nested level is a Configuration provider.

class C1(containers.DeclarativeContainer):
    # deps = providers.DependenciesContainer()
    config = providers.Configuration()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant