📝 Bug: `redis.asyncio.Redis` type hint is not injected and fails validation (#3065)
Describe the bug
Annotating a handler argument with
redis.asyncio.Redis — the obvious type for the connection — does not inject it. Instead the argument is treated as a message field and fails validation. The working annotation is faststream.redis.annotations.Redis, which is a different symbol with the same name.The two names are identical, the import paths differ, and nothing in the failure points at the fix.
How to reproduce
from redis.asyncio import Redis
@broker.subscriber(stream=StreamSub("stream", group="group", consumer="consumer"))
async def handler(msg: RedisStreamMessage, redis: Redis) -> None:
...
vs. the version that works:
from faststream.redis.annotations import Redis
Real usage
A worker running
faststream[redis] in production hit this and left a warning to their future selves in the handler docstring — SW-Maestro-17th-HBB/Kkori-AI, worker/src/main.py#L186-L191:They also import it aliased —redis는 FastStream 이 Context 로 넣어주는 커넥션이다.redis.asyncio.Redis를 그대로 힌트로 쓰면 주입되지 않고 검증 오류가 난다.
("redisis the connection FastStream injects via Context. If you useredis.asyncio.Redisdirectly as the hint, it is not injected and you get a validation error.")
from faststream.redis.annotations import Redis as InjectedRedis — which suggests the name collision cost them enough to want it visible at the call site.Expected behavior
Two things would each be enough on their own:
1. Documentation — the Redis pages show
Redis in examples without making the import path explicit enough to survive a copy-paste. A short note that the annotation comes from faststream.redis.annotations, and that the same-named driver class will not work, closes it.2. A better failure — when an argument is annotated with a broker client class that has a matching FastStream annotation, say so in the error instead of failing validation on a missing message field.
Additional context
Found by reading a real user's source, not reported by them — they worked around it and moved on, which is the reason this kind of papercut stays invisible. Companion finding: #3064.
@IvanKirpichnikov — the docs half is cheap; the error-message half is your call.
#bug #documentation #good_first_issue #redis #faststream #ag2ai
sent via relator