Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modern_di_grpc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def fetch_di_container() -> Container:

def _ensure_context_provider(container: Container) -> None:
# Register grpc_context_provider once (idempotent) so ServicerContext injects out of the box.
if container.providers_registry.find_provider(ServicerContext) is None:
if container.find_provider(ServicerContext) is None:
container.add_providers(grpc_context_provider)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
dependencies = [
# The committed test stubs under tests/protos refuse to import below 1.82.1.
"grpcio>=1.82.1,<2",
"modern-di>=3.1,<4",
"modern-di>=4,<5",
]
version = "0"

Expand Down
3 changes: 1 addition & 2 deletions tests/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ContextReader:


def _make_context_reader(context: ServicerContext | None = None) -> ContextReader:
# `context` is wired from grpc_context_provider (ContextProvider(ServicerContext, REQUEST));
# the `| None = None` default lets it construct at validate time when no context is set.
# The default applies only when no DIInterceptor has registered grpc_context_provider on the container.
return ContextReader(peer=context.peer() if context is not None else "no-context")


Expand Down
2 changes: 1 addition & 1 deletion tests/test_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def behavior(_request: object, _context: ServicerContext) -> str:
def test_di_interceptor_registers_context_provider_idempotently() -> None:
container = Container(groups=[Dependencies])
DIInterceptor(container)
assert container.providers_registry.find_provider(ServicerContext) is not None
assert container.find_provider(ServicerContext) is not None
# Second construction on the same container must hit the idempotent-skip branch, not
# try (and fail) to register grpc_context_provider a second time.
DIInterceptor(container)
Expand Down
Loading