Skip to content

4.8.2 broke different case for providers.Container usage where declaration is not at class root level #379

Closed
@rmk135

Description

@rmk135

Instead of opening new issue I'll comment right here, because 4.8.2 broke different case for providers.Container usage where declaration is not at class root level.

Here is somewhat simplified example:

from dependency_injector import providers, containers


class NestedContainer(containers.DeclarativeContainer):
	settings = providers.Configuration()

	print_settings = providers.Callable(
		lambda s: print(s),
		settings,
	)


class TestContainer(containers.DeclarativeContainer):
	settings = providers.Configuration()

	root_container = providers.Container(
		NestedContainer,
		settings=settings,
	)

	not_root_container = providers.Selector(
		settings.container,
		using_factory=providers.Factory(
			NestedContainer,
			settings=settings,
		),
		using_container=providers.Container(
			NestedContainer,
			settings=settings,
		)
	)


container = TestContainer(settings=dict(
	container='using_factory',
	foo='bar'
))

container.root_container().print_settings()  # Prints {'container': 'using_factory', 'foo': 'bar'}
container.not_root_container().print_settings()  # Prints {'container': 'using_factory', 'foo': 'bar'}

container = TestContainer(settings=dict(
	container='using_container',
	foo='bar'
))

container.root_container().print_settings()  # Prints {'container': 'using_container', 'foo': 'bar'}
container.not_root_container().print_settings()  # Prints {} after 4.8.2

We expect here for all prints to be equal, and 4.8.2 breaks it. Workaround is using providers.Factory, but still case is some kind of a regression.

Originally posted by @approxit in #354 (comment)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions