Authentication router with OAuth2PasswordRequestForm dependency route breaks /docs when included inside startup event #292
Unanswered
richardnm-2
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was adding a security layer on an app that I was working on and had already tested basic functionality deployed into Lambda. I'm using a container image.
When I added my security layer that I borrowed from another app running on a live server, my app still worked when making requests to it, but the
/docs
route started to throw an error:Failed to load API definition
Fetch error. Internal server error /openapi.json.
I dynamically include my routers to my app instance using
app.include_routers()
, and I did it inside thestartup
event.Local testing done, all tests passed, the frontend still worked as expected but the
/docs
were gone.I narrowed the error down to the imports being performed inside the
startup
event, but only when I have theOAuth2PasswordRequestForm
dependency.Here is a minimal reproducible example, using the non-annotaded example in the FastAPI (v0.95) documentation
Removing the
OAuth2PasswordRequestForm
dependency, the/docs
work again, and including the routers outside of thestartup
event also.Maybe I missed something regarding lifespans. Also have the same structure running on another project under
Nginx
, and the pattern works.It's not actually a big deal to include the
routers
outside the event, but I wonder why this conflicts with the OAuth2PasswordRequestForm.Beta Was this translation helpful? Give feedback.
All reactions