-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with FastAPI problems #53
Comments
@xKlask |
@xKlask great job again! I fix serialization Issue from Propan side, but ignoring router lifespan from FastAPI side is a bug of that framework. I fix it too and will try to PR it to FastAPI. |
@xKlask with 0.1.2.13 version I fixed messages serialization. router = RabbitRouter("amqp://guest:guest@localhost:5672")
app = FastAPI(lifespan=router.lifespan_context) |
@Lancetnik can you read email, pls? |
To begin with, I would like to say a great thanks to the developer, Propan is magnificent. Very long thought to simplify the work and bring in a convenient format, but never got it together.
I had some problems with the integration with FastAPI, probably due to incomplete documentation or other things.
FastAPI 0.96.0
Propan 0.1.2.12
We get the following error:
This is because the "lifespan" is not cast to the router, but can only be put at the stage of creating the application. Unlike the deprecated "on_startup".
We fix this by adding a router lifespan at the stage of creating the application:
or send all events like example from tests:
We get a pydantic validation error because we take a byte message and don't parse it.
Because the file "propan/fastapi/core/route.py" on line 35 has hardcode _raw=True
broker.handle(path, _raw=True, **handle_kwargs)(handler)
Since we don't convert bytes to dict, pydantic can't validate (which would be very convenient)
changing the _raw flag to False doesn't fix it, because the app method on line 75 is waiting for a "NativeMessage" object
async def app(message: NativeMessage) -> Any:
But the decode method only passes the dict contained in the .body
My crappy fix for the situation is _raw=False and add a check in the app method:
Hopefully we can find a good solution for easy integration with FastAPI
The text was updated successfully, but these errors were encountered: