Add support for Fast Stream Depends#898
Conversation
dad7b0f to
575d0e4
Compare
There was a problem hiding this comment.
Bug: Falsy Dependency Extraction Fails
The _get_marker_from_parameter function fails to extract falsy but valid dependencies (e.g., False, 0, "", or a falsy _Marker) from Depends wrappers. The if _marker := marker_extractor(marker): line's implicit truthiness check prevents marker from being updated when the extracted dependency is falsy. This leaves the original Depends object, causing the subsequent isinstance(_Marker) check to fail, unlike the previous implementation.
src/dependency_injector/wiring.py#L616-L620
python-dependency-injector/src/dependency_injector/wiring.py
Lines 616 to 620 in b414ef7
Was this report helpful? Give feedback by reacting with 👍 or 👎
|
Thanks for contribution! |
|
With raw Depends it doesn't work in FastStream. @broker.subscriber("hello_world")
@inject
async def on_hello_world(
input: Input,
service: Service=Depends(Provide["service"]),
):
print(f"Service: {service}")Crashes with an error: But with cast=False all works fine: @broker.subscriber("hello_world")
@inject
async def on_hello_world(
input: Input,
service: Service=Depends(Provide["service"], cast=False),
):
print(f"Service: {service}") |
Thank You for the observation! Please, include source where you import |
|
There was a kafka broker in my test: Actually, this issue can only be repeated with the FastDepends only by adding @fast_depends.inject: @fast_depends.inject
@inject
async def apply_coefficient(
a: int,
b: str,
coefficient_provider: CoefficientService = Depends(
Provide[Container.service]
),
) -> float:
return a * coefficient_provider.get_coefficient()And now it crashes with the same error: |
Inspired by PR 854. A slightly cleaner solution, where FastApi separated from Fast Stream properly. Even though they were together at some point, now Fast Stream - is a separate library after all.