Skip to content

Conversation

@AndrianEquestrian
Copy link
Contributor

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.

@ZipFile ZipFile changed the base branch from master to develop June 1, 2025 22:57
@AndrianEquestrian AndrianEquestrian force-pushed the better-fast-stream-depends-integration branch from dad7b0f to 575d0e4 Compare June 14, 2025 11:19
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@ets-labs ets-labs deleted a comment from cursor bot Jun 15, 2025
@coveralls
Copy link

coveralls commented Jun 15, 2025

Coverage Status

coverage: 94.584% (-0.04%) from 94.62%
when pulling b414ef7 on AndrianEquestrian:better-fast-stream-depends-integration
into f2da51e on ets-labs:develop.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

for marker_extractor in MARKER_EXTRACTORS:
if _marker := marker_extractor(marker):
marker = _marker
break

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

@ZipFile
Copy link
Contributor

ZipFile commented Jun 16, 2025

Thanks for contribution!

@ZipFile ZipFile merged commit b411807 into ets-labs:develop Jun 16, 2025
14 checks passed
@Totorokrut
Copy link

With raw Depends it doesn't work in FastStream.
Such test:

@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:

pydantic_core._pydantic_core.ValidationError: 1 validation error for ResponseModel response Input should be a valid dictionary or instance of ResponseModel [type=model_type, input_value=<dependency_injector.wiri...bject at 0x78deeb6cdf70>, input_type=Provide] 

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}")
@AndrianEquestrian
Copy link
Contributor Author

AndrianEquestrian commented Aug 9, 2025

With raw Depends it doesn't work in FastStream. Such test:

@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:

pydantic_core._pydantic_core.ValidationError: 1 validation error for ResponseModel response Input should be a valid dictionary or instance of ResponseModel [type=model_type, input_value=<dependency_injector.wiri...bject at 0x78deeb6cdf70>, input_type=Provide] 

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 broker decorator from, I think I should investigate it, in order to determine the cause of the issue.

@Totorokrut
Copy link

There was a kafka broker in my test: broker = KafkaBroker("localhost:32833")

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: pydantic_core._pydantic_core.ValidationError: 1 validation error for ResponseModel ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants