fix(api): restore Depends(get_db) — db: Any = None is never injected - #847
Open
libingtong wants to merge 1 commit into
Open
fix(api): restore Depends(get_db) — db: Any = None is never injected#847libingtong wants to merge 1 commit into
db: Any = None is never injected#847libingtong wants to merge 1 commit into
Conversation
…= None` This reverts f0874c3 ("convert Depends(get_db) to db: Any = None across API endpoints to release connection pool early"). That commit changed 275 endpoint signatures but only touched app/api/**; no mechanism was added to supply the session. FastAPI treats an un-annotated `db: Any = None` parameter as an optional *query* parameter, so `db` is always None at runtime and every endpoint that touches it raises: AttributeError: 'NoneType' object has no attribute 'execute' AttributeError: 'NoneType' object has no attribute 'add' Confirmed on a deployment running current main — both are public endpoints: POST /api/enterprise/check-email-exists -> 500 POST /api/sso/session -> 500 POST /api/sso/session breaking is particularly damaging because the login page calls it before /sso/config (frontend/src/pages/Login.tsx), so the whole SSO provider section silently fails to render. Endpoints that never declared a `db` parameter and open their own transaction (e.g. POST /api/auth/login) are unaffected, which is why basic login still works and the regression is easy to miss. Reverting restores the working behaviour. If the connection-pool optimisation is still wanted, it needs each converted endpoint to actually acquire a session in its body (e.g. `async with transaction() as db:`) rather than only changing the signature — that is a much larger change and should land with tests that exercise the converted endpoints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
f0874c3 ("convert
Depends(get_db)todb: Any = Noneacross API endpoints to release connection pool early") changed 275 endpoint signatures but only touchedapp/api/**; no mechanism was added to supply the session.FastAPI treats an un-annotated
db: Any = Noneparameter as an optional query parameter, sodbis alwaysNoneat runtime and every endpoint that touches it raises:Reproduction
Confirmed on a deployment running current
main. Both are public, unauthenticated endpoints:Why it is easy to miss
Endpoints that never declared a
dbparameter and open their own transaction — e.g.POST /api/auth/login— are unaffected, so basic email/password login keeps working.POST /api/sso/sessionbreaking is the most damaging case: the login page calls it before/sso/config(frontend/src/pages/Login.tsx), so the entire SSO provider section silently fails to render with no visible error.This PR
Reverts f0874c3 to restore working behaviour.
If the connection-pool optimisation is still wanted, each converted endpoint needs to actually acquire a session in its body (e.g.
async with transaction() as db:) rather than only changing the signature. That is a substantially larger change and would benefit from tests that exercise the converted endpoints — none currently cover them, which is why this shipped.