Skip to content

fix: P27 — attribute subscriber-config warnings to the user's call site#69

Merged
lesnik512 merged 1 commit into
mainfrom
worktree-p27-warning-stacklevel
Jun 13, 2026
Merged

fix: P27 — attribute subscriber-config warnings to the user's call site#69
lesnik512 merged 1 commit into
mainfrom
worktree-p27-warning-stacklevel

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

Closes the audit's last skipped item, P27. The five misconfiguration UserWarnings in _validate_subscriber_config (REJECT_ON_ERROR + retry, NACK_ON_ERROR + NoRetry, max_deliveries without retry, lease_ttl <= max_fetch_interval) used a static stacklevel=4. That's correct only for the direct @broker.subscriber(...) path; through the FastAPI OutboxRouter (which adds frames) it landed on a faststream-internal frame, so the warning pointed at library code instead of the user's decorator line.

Fix

Switched to warnings.warn(..., skip_file_prefixes=_WARN_SKIP_PREFIXES) (Python 3.12+; requires-python is >=3.13). The prefixes are the faststream_outbox and faststream package dirs, so the warning is attributed to the first caller frame outside both packages — correct for the direct and router paths, with no fragile frame-counting.

_WARN_SKIP_PREFIXES = (
    str(Path(__file__).parent.parent),       # faststream_outbox/
    str(Path(faststream.__file__).parent),   # faststream/
)

Test

test_subscriber_misconfig_warning_attributed_to_user_via_fastapi_router registers a misconfigured subscriber through the FastAPI OutboxRouter and asserts the captured warning's filename is the test file (the user), not a package frame. Mutation-verified: red under the old stacklevel=4 (it pointed at a faststream frame), green with skip_file_prefixes.

Test Plan

  • New test green; verified red under the reverted stacklevel=4
  • Existing pytest.warns-based factory tests unaffected (they assert message, not location)
  • Full dockerized suite: 473 passed, 100% coverage; ruff + ty clean

Behavior unchanged — the warnings still fire identically; only their reported source location is corrected. Next: the P29+P30 test-broker cleanup PR.

🤖 Generated with Claude Code

The five misconfig UserWarnings in _validate_subscriber_config used a static
stacklevel=4, correct only for the direct @broker.subscriber path. Through the
FastAPI OutboxRouter (which adds frames) it landed on a faststream-internal
frame, so the warning pointed at library code instead of the user's decorator.

Switch to warnings.warn(..., skip_file_prefixes=_WARN_SKIP_PREFIXES) (3.12+),
skipping frames inside faststream_outbox and faststream — the warning is now
attributed to the first caller frame outside both packages, correct for both
the direct and router paths. requires-python is >=3.13, so the param is available.

Adds test_subscriber_misconfig_warning_attributed_to_user_via_fastapi_router
(mutation-verified: red under the old stacklevel=4). Full suite: 473 passed,
100% coverage; ruff + ty clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit cd66145 into main Jun 13, 2026
3 checks passed
@lesnik512 lesnik512 deleted the worktree-p27-warning-stacklevel branch June 13, 2026 10:05
lesnik512 added a commit that referenced this pull request Jun 13, 2026
Covers the post-0.9.0 work: suspected findings S1–S5 (#68), the P27 warning-
attribution fix (#69), and the P29/P30 test-broker cleanup (#70). Patch bump —
fixes/hardening only, no new breaking changes; the one opt-in behavior change is
validate_schema() now catching partial-index predicate drift.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lesnik512 added a commit that referenced this pull request Jun 13, 2026
…ings (#71)

The 2026-06-12 code audit shipped across 0.9.0 (#61/#66/#67) and
0.9.1 (#68/#69/#70), but the invariant docs still described pre-fix
behavior. Sync the drift the audit flagged plus the drift its own
fixes introduced, and retire the now-resolved findings doc.

CLAUDE.md / architecture:
- relay: `_OutboxConfigError` no longer "rides AcknowledgementMiddleware
  to the nack path" — the worker catches it, logs at ERROR, and the row
  retries via lease expiry, not the retry_strategy (P18). Fixed in both
  CLAUDE.md and architecture/relay.md.
- terminal-write API: `delete_with_lease(conn, …)` /
  `mark_pending_with_lease(conn, …)`, not the `*_with_conn` names.
- NOTIFY: over-long table names now raise ValueError at construction
  (P7), not "silently lose NOTIFY and degrade to polling".
- engine ownership: drop the phantom `EngineState` holder and the dead
  `OutboxBrokerConfig.disconnect()` (removed in P24).
- schema: note the P8 `<table>_lease_ck` CHECK; validate_schema now
  also probes partial-index predicates (S2).
- drain regression-test references point at the real test names (T8
  added them to test_fake.py; integration covers the Postgres path).
- timers NOTIFY-skip: "genuinely future-dated" wording (a past/zero
  activate_at/in does fire NOTIFY).

Archive:
- move planning/active/2026-06-12-code-audit-findings.md →
  planning/archived/ with status: shipped + PR/release provenance.
- repoint the two release-notes "See also" links to archived/.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant