abhisheksharma2411/justonce: v0.2.0 — retention and reclaim correctness
Year: 2026
Type: software
Abstract: Upgrade if you use the SQLite or Postgres store Two defects fixed here could let a retry produce a second effect — the exact failure mode this library exists to prevent. Both were reported by an outside contributor. retention_seconds was ignored, so keys were forgotten early A completed record kept the claim lease's expires_at, and sweep() reads that same column for terminal records. So a record was deleted one claim-TTL after it was written, however long retention was configured for. Once the key is gone, a retry arriving inside the intended retention window looks like a first attempt and runs again. expires_at is now replaced when a record becomes terminal, and a terminal record written with no retention is never swept. (#39, #59) An expired lease could be reclaimed by a different payload The reclaim UPDATE did not compare request_hash, so a caller whose request differed from the original could inherit the key and execute — precisely what an idempotency key is for. Reclaim now requires a matching fingerprint; a diverging caller loses the race and meets the recorded hash. (#40, #59) Postgres responses failed to decode depending on which store created the table PostgresStore declared response as JSONB while DjangoStore declared it TEXT, so whichever created the table first won and the other's reads broke. The DDL is aligned, and both stores now read response::text so the value is decoded exactly once regardless of column type. (#57) Added DjangoStore — reuses Django's existing database connection. store.in_ambient_transaction() tells you whether the store shares a transaction with your business writes, which is the thing that quietly breaks idempotency when it does. Runnable FastAPI payment example (examples/fastapi_payment.py) exercising the retry, crash, divergence and concurrency paths end to end. (#38) Store selection guidance in the README — including that SqliteStore() with no path is in-memory by default, so it forgets every key on restart. (#58) Changed Store.complete() and Store.fail() now take retention_seconds, so retention is applied where a record becomes terminal rather than inferred afterwards. Custom store implementations need updating. Strict mypy passes across the package. A note on the tests Two existing conformance tests were asserting the #39 bug — they swept a terminal record on its claim TTL and called that retention, so they passed because of the defect. They have been rewritten, and the new tests were each watched failing against unfixed code before being trusted. Verified before release: 208 tests pass, including 70 Postgres conformance tests against a real PostgreSQL 16; ruff and strict mypy clean. Full changelog: https://github.com/abhisheksharma2411/justonce/blob/main/CHANGELOG.md Compare: https://github.com/abhisheksharma2411/justonce/compare/v0.1.0...v0.2.0
Authors: Abhishek Sharma, Ahmed Balde, B. Machagiri
Language: English
Subfield: Computer Networks and Communications
Field: Computer Science
Domain: Physical Sciences
Open Access status: green
OpenAlex ID: W7203933820
