Skip to content

Add ORM after_commit callbacks and repository ADR guidance - #262

Open
tmgbedu wants to merge 4 commits into
mainfrom
task/orm-after-commit
Open

tmgbedu wants to merge 4 commits into
mainfrom
task/orm-after-commit

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Applications can now register work that runs only after database changes commit with await DB.after_commit(callback, name=None) or await connection.after_commit(callback). Sync and async callbacks run in registration order after the outermost commit; rollback discards callbacks from the affected scope, and registration without an active transaction runs immediately.

Integrates with manual transactions and transaction context managers, including savepoints and explicit transaction-object methods. Releases the root connection before dispatch, preserves callback-created transactions, and clears callback state after errors, cancellation, invalidation, close, and reconnect.

Carries the repository guidance migration into AGENTS.md, keeps MCP server configuration in .mcp.json, and adds ADR 001 with the API contract, implementation rationale, and indexed decision record.

Validation: 431 SQLite and callback tests passed, with 6 skipped; 49 focused callback/transaction tests passed; Ruff lint and format checks passed on modified Python files; basedpyright reported 0 errors and 0 warnings. Independent QA probes covered open savepoints, inherited task contexts, callback reentrancy, and cancellation. Live MySQL/Postgres suites were not run.

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…d pointer, reword ADR

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JaU6B7ud65487jp3m8n2Rm

tmgbedu commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Review of the after-commit change: the design looks sound, and ordering, scoped rollback and error handling are well covered by the tests. Findings, with fixes pushed to claude/upbeat-fermi-wuok6j (commit 0d9025f, on top of this PR's commit):

Must fix (addressed)

  1. CLAUDE.md → AGENTS.md rename left Claude Code without repo guidance. Added a CLAUDE.md containing @AGENTS.md.
  2. .mcp.json doesn't exist on main or in this diff. Removed the claim from AGENTS.md, the ADR and the ADR index. The deleted Keera section was not restored.
  3. KeyError on unregistered transactions in after_commit and _finish_transaction. They now use frames.get(...) / in frames; callbacks registered in an untracked transaction run immediately, and an ORM savepoint inside one acts as its own root. Tests added.

Should fix (addressed)

  • Transaction.commit() now releases the connection only when _owns_connection is true.
  • The connection property no longer mutates the ContextVar.
  • Merged the two TYPE_CHECKING imports in DB.py (there is no .pyi stub for DB).
  • Added a test for nested rollback followed by a new registration.
  • ADR reworded for clarity.

37 tests in test_after_commit.py pass; Ruff lint and format pass. Live MySQL/Postgres suites were not run.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants