FastAPI - Application Hangs upon combining pydantic.Model and fastapi.router #5320
Replies: 2 comments
-
|
This is the first time I've seen someone does that. I don't think it's good and it seens FastAPI/Starlette doesn't like it either |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Printing pydantic models evaluates them. When that evaluation has a problem -> crash. To debug that kind of stuff make sure you aren't using the compiled pydantic: e.g. check the output of:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Given a FastAPI application, with pydantic models at the URIs input parameters, there are two different behaviors that are being observed, depending on if the request's body is read or not in
@app.middleware("http").Given a simple application:
After executing the above script, and bringing up the server, the following behaviors are being observed:
The above table, indicates that when the
pydantic.Modelis being used to define the input parameter model, then the application Hangs when the Model is not an extension of thefastapi.requests.Requestand the@app.middlewareis logging the body.On the other hand, when there
@app.middlewareis not logging the body, then the application works fine, and without having the need to extend the Model to inherit from thefastpi.requests.Request.Resolution:
a. Based on the above, is that when the
@app.middlewareis in place and attempts to log the body, then thefastapi.responses.RedirectResponsefails to redirect, and the request/application hangs. Extending the parameters to inherit fromfastapi.responses.Reqeustmakes the redirection take place, but then the input loses itsModelattributes, and results to runtime errors.b. It is very weird though, that when the
@app.middlewareis in place and DOESN'T log the body, then the application works fine, without the need to even make the Models inherit fromfastapi.requests.Request.Is the above a bug (Resolution-> a) on Starlette's
fastapi.responses.RedirectResponse?How it be that the behavior of the application changes so drastically upon logging the request body on the
@app.middleware("http")?If the above is not a bug, is it possible to utilize the router, with model, and redirect correctly to sub-resources?
Beta Was this translation helpful? Give feedback.
All reactions