Closed tcmRyan closed 1 week ago
@tcmRyan sorry, but I don't think, that the problem is in lifespan - FastStream doesn't analize this method
Also, current snippet doesn't reproduce the problem
from contextlib import asynccontextmanager
from fastapi import FastAPI
from faststream.rabbit.fastapi import RabbitRouter
rabbit_router = RabbitRouter()
@asynccontextmanager
async def lifespan(app: FastAPI):
await rabbit_router.broker.start()
yield
rabbit_router.broker.close()
app = FastAPI(lifespan=lifespan)
app.include_router(rabbit_router)
Can you try to localize the problem and share MRE with me?
Closing the issue. Looks like this was because I had an issue in a decorator I have elsewhere to do custom ack/nack
@tcmRyan did you solve your problem?
TLDR; Yup, just had to delete some code, which always feels nice.
I wrote a wrapper around Faststream so that I can use rabbit with Fanout exchanges similar to the Blinker library. My issue was when I tried to leave space for custom ack/hack work, but since Im not doing anything the Faststream doesn't already do, Im just going to punt on the problem.
This was the code causing the issue:
def subscribe(self, subscriber, broker):
broker.subscriber(subscriber.queue, self.exchange)(self.handler(subscriber.fn))
@staticmethod
def handler(fn):
async def base_handler(body: Any, msg: RabbitMessage):
try:
await fn(body)
await msg.ack()
except Exception:
await msg.nack()
return base_handler
Describe the bug After creating a RabbitRouter and calling broker.start() inside the FastAPI lifespan, Faststream throws an import error in
faststream/broker/fastapi/get_dependant.py", line 32, in get_fastapi_native_dependant
How to reproduce Include source code:
And/Or steps to reproduce the behavior:
Expected behavior Fast API would not throw a Pydantic Error when starting the broker.
Observed behavior Fast API throws a PydanticUndefinedAnnotation error
Screenshots If applicable, attach screenshots to help illustrate the problem.
Environment Include the output of the
faststream -v
command to display your current project and system environment.Additional context Provide any other relevant context or information about the problem here.