feat: give the retriable-error predicate its own seam#22
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure is_retriable(exc) -> bool in db_retry/retriable.py; walks __cause__/__context__ chain with cycle guard to classify retriable DBAPIErrors without a live database.
Reduce test_postgres_retry to two rows (40001 retriable, 40002 non-retriable). Delete test_postgres_retry_advanced_alchemy (covered by test_retriable.py). Remove unused advanced_alchemy imports.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What & why
Moves the retriable-error decision behind a pure
is_retriable(exc) -> boolseam so it's tested in memory instead of through a live Postgres round-trip. The classification logic (unwrapDBAPIError, classify the asyncpg error, walk the__cause__/__context__chain) was the deepest code in the package but sat behind the wrong seam — its only test surface was a stored proc raising a chosen SQLSTATE.Behaviour-preserving refactor: same retriable classes in, same out, same logs, same surfaced exception.
Changes
db_retry/retriable.py(new) — pureis_retriable+ namedRETRIABLE_ASYNCPG_ERRORStaxonomy. No logger, no side effects. Walk order and cycle guard lifted verbatim.db_retry/retry.py— consumes the seam via a thin_log_and_decidewrapper that preserves both debug lines verbatim; deletes the two old private functions.is_retriableis an internal seam — not added to__all__; the package keeps its five public symbols.tests/test_retriable.py(new) — in-memory classification matrix built from realDBAPIError/asyncpg types (40001, 08000, an 08-subclass, non-retriable, re-wrappedRepositoryError.__cause__chain,__context__-only, a__cause__cycle, bare non-DBAPI).tests/test_retry.py— trimmed to wiring proofs: one parametrized retriable/non-retriable pair + theretries=override, proving the decorator wires the predicate into tenacity andreraise=Truesurfaces the original error.architecture/retriable.md; cause-chain prose moved out ofretry.md;README.mdcapability index updated;architecture/glossary.mdauthored with the Retriable error term.planning/changes/2026-06-26.01-retriable-error-seam/(design.md+plan.md).Verification
just test(Docker Postgres) → 24 passed, 100% coveragejust lint-ci→ all checks pass (ruff format/check, ty, eof-fixer, planning)🤖 Generated with Claude Code