Skip to content

fix(db): failed commits drop the response's background work; read-only finalization keeps loaded rows; savepoint rollback clears the write marker - #823

Merged
antosubash merged 4 commits into
mainfrom
fix/db-review-sessions
Nov 4, 2026
Merged

antosubash merged 4 commits into
mainfrom
fix/db-review-sessions

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

  • db: background tasks still run and commit after the request commit fails (500) #807 (behaviour change): when the request commit fails in CommitBeforeResponseMiddleware, the original response is now unwound. Its background tasks and streaming body never run, and exactly one JSON 500 is sent, even if inner code swallows the signal. Before, the endpoint's background tasks still ran and their writes were committed after the client got a 500.
  • db: read-only finalization expires loaded rows before a StreamingResponse/background task reads them (MissingGreenlet) #808 (behaviour change): read-only finalization closes the transaction (SessionTransaction.close()) instead of calling session.rollback(). Loaded objects therefore aren't expired, and a StreamingResponse body or background task can read already-loaded attributes without a MissingGreenlet. The connection is still released before the body streams. Loaded objects keep their values: use populate_existing() to refresh them.
  • db: a write rolled back in a savepoint still marks the request written, so on_commit callbacks fire #809: the write marker is tracked per transaction level:
    • a write rolled back with its savepoint no longer forces a commit or runs the outer on_commit callbacks;
    • a released savepoint's marker merges into its parent;
    • a mid-request commit keeps the callbacks already queued, as before;
    • mark_written never begins a transaction;
    • the tenants owner guard now goes through mark_written instead of setting the flag directly.
  • docs/database/sessions.md, docs/framework-conventions.md, the database skill, the get_db docstring and the CHANGELOG are updated.

Verification

  • Local CI: make lint and the docs build passed, along with these suites:
    • make test-py: 7736 passed
    • make test-js: passed
    • make doctor: clean
    • e2e: 98 passed against a live API + Vite
  • Not browser-tested: this changes the DB layer only and has no UI.
  • Verification report: https://claude.ai/artifact/DmpUQLTqjrWGv4cRLpTaeQ

Report links are Claude Artifacts and start private; the author can share them from claude.ai/code/artifacts if reviewers need access.

Closes #807
Closes #808
Closes #809

Test plan

  • CI is green

https://claude.ai/code/session_01FXHA3ZicrtZ4C5QPEgxfgq

…y finalization keeps loaded rows; savepoint rollback clears the write marker (#807, #808, #809)

Claude-Session: https://claude.ai/code/session_01FXHA3ZicrtZ4C5QPEgxfgq
A commit issued mid-request (fastapi-users commits in create/update) cleared the write marker, so finalization took the read-only path and dropped the request's on_commit callbacks (session-version eviction, UserCreated). Root commits now leave an untracked mark that only finalization or a full rollback clears. mark_written no longer begins a transaction; write listeners are registered once per session class. A swallowed commit-abort still yields exactly one JSON 500.

Claude-Session: https://claude.ai/code/session_01FXHA3ZicrtZ4C5QPEgxfgq
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-04T16:57:09.755627Z 350ff9c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 350ff9c
Status: ✅  Deploy successful!
Preview URL: https://5a25fdfd.simple-module-python.pages.dev
Branch Preview URL: https://fix-db-review-sessions.simple-module-python.pages.dev

View logs

@antosubash
antosubash merged commit 99ff477 into main Nov 4, 2026
17 checks passed
@antosubash
antosubash deleted the fix/db-review-sessions branch November 4, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant