fix: Depends(db) resolved twice in one request opens two sessions and silently discards writes

This commit is contained in:
2026-08-28 12:58:47 -04:00
parent 23dc5c86b2
commit 1c806cccd9
4 changed files with 139 additions and 17 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ db = Database(
## Committing before the response
[`db.install(app)`](../reference/db.md#fastapi_toolsets.db.Database) adds a middleware that commits the request's session when the response starts, after the endpoint returns and before the body is sent. With the middleware installed, the dependency does not commit again.
[`db.install(app)`](../reference/db.md#fastapi_toolsets.db.Database) adds a middleware that commits the request's session when the response starts, after the endpoint returns and before the body is sent. The dependency commits only if the middleware did not: when a function-scoped dependency unwinds before the response, or when the response never passes through the middleware. Either way the request is committed exactly once.
The request is committed as a single transaction: