Skip to content

F22.9 — Django adapters with safe parsing and ownership

State Closed
Parent E22
Iteration Release 9
Start Date 2026-11-14
Closed Date 2026-11-16
Predecessors F22.8 for shared-policy changes

Stories: 3 Closed

Story State Depends on
S22.9.1 — Claim before execution Closed (2026-11-14) —
S22.9.2 — Use unambiguous values Closed (2026-11-14) —
S22.9.3 — Thin auth and transfer composition Closed (2026-11-16) S22.8.2

Fix cache/claim edge cases and remove duplicate neutral policy while keeping native Django extension points.

Context

drf/idempotency.py:54-58 returns the execute sentinel when a record expires after a failed claim, without owning the slot. drf/pagination.py:43 accepts strings such as --1 and ² before int raises. models/cache.py joins composite keys with dots, so different tuples collide. Auth routes and transfer mixins also combine several responsibilities.

S22.9.1 — Claim before execution

State: Closed (2026-11-14)

Retry the atomic cache claim when an observed entry disappears. Keep in-flight, mismatched-body and completed replay outcomes distinct.

Acceptance:

  • A controlled failed-add/expired-get interleaving allows execution only after a successful claim; competing callers never both execute under that interleaving.
  • Existing replay, scope isolation, TTL, mismatch and in-flight cases still pass.
  • The solution does not claim to solve execution beyond claim expiry without a separately chosen lease contract.
  • A vanished entry retries the claim, up to 3 attempts in all; after the last, the store raises IdempotencyKeyInFlight (409). Public signatures, the cache_key format and the 409/422/replay outcomes are unchanged.

Outcome: CacheIdempotencyStore.record_or_replay returns the execute sentinel only after its own cache.add succeeds.

S22.9.2 — Use unambiguous values

State: Closed (2026-11-14)

Parse page sizes with a deliberate invalid-input policy, and use structural composite cache keys while preserving supported scalar normalization.

Acceptance:

  • Both pagination classes handle malformed signs, Unicode digits, huge values, zero, negatives and normal values without an unhandled conversion exception.
  • Load/set/get distinguish (a.b, c) from (a, b.c) and preserve documented scalar lookups.
  • Page size is clamped, never rejected: only an ASCII -?[0-9]+ value counts; anything else, zero or a negative yields the default; a positive value of any length yields at most the cap. Composite keys are a tuple[str, ...] of str(v); the cache is in-process only, so nothing migrates.

Outcome: --1, ² and over-long values no longer raise, and ٣ no longer parses as 3.

S22.9.3 — Thin auth and transfer composition

State: Closed (2026-11-16) · Depends on: S22.8.2

Consume auth policy/codecs from F22.8. Separate transfer import/export/batch concerns only where native mixin composition stays clear. Reuse web wire policy; keep ORM transactions, serializer validation and Django sessions local.

Acceptance:

  • Adapter integration cases retain cookie/CSRF, session rotation, auth-denial and readiness behavior.
  • Import/batch dry runs, row-index errors, authorization, rollback and exports retain framework-level coverage.
  • Large queryset/export measurements show query count and peak memory; a refactor must not accidentally add one query per row.

Settled contract: the Django adapter already consumes the S22.8.2 auth pieces and rn_forge.web wire policy, and transfer.py is already six mixins over one base, so no production code changed. ORM lookups, transaction.atomic, serializer validation, Django sessions, cache counters and CSRF stay local. Export and batchGet cost a constant number of queries; batchCreate costs 2 per row, batchUpdate 1 and batchDelete 1. Export stays constant for the forward relations its resource reads (S24.1.2).

Outcome: TestQueryCounts pins those slopes on SQLite and PostgreSQL; a 9,000-row export costs 2 queries and 3.6 MB traced peak.

Acceptance

  • S22.9.1: A controlled failed-add/expired-get interleaving allows execution only after a successful claim; competing callers never both execute under that interleaving.
  • S22.9.2: Both pagination classes handle malformed signs, Unicode digits, huge values, zero, negatives and normal values without an unhandled conversion exception.
  • S22.9.3: Adapter integration cases retain cookie/CSRF, session rotation, auth-denial and readiness behavior.