Skip to content

Comments

docs: Add REQUEST scope demos to FastAPI and Flask examples#476

Merged
mikelane merged 1 commit intomainfrom
issue-339-request-scoping-middleware
Feb 7, 2026
Merged

docs: Add REQUEST scope demos to FastAPI and Flask examples#476
mikelane merged 1 commit intomainfrom
issue-339-request-scoping-middleware

Conversation

@mikelane
Copy link
Owner

@mikelane mikelane commented Feb 7, 2026

Summary

  • Add RequestContext service with Scope.REQUEST to both FastAPI and Flask example apps
  • Add /context endpoint demonstrating per-request unique IDs via request scoping
  • Update example READMEs with request scoping documentation sections and API endpoint docs

Context

The middleware integration for request scoping (issue #339) is already fully implemented in python/dioxide/fastapi.py and python/dioxide/flask.py with 40 passing integration tests. The remaining gap was that example applications did not demonstrate Scope.REQUEST usage. This PR fills that gap.

The production code includes:

  • DioxideMiddleware (FastAPI): ASGI middleware creating ScopedContainer per request
  • configure_dioxide() (Flask): Sets up before_request/teardown_request hooks for scope lifecycle
  • Inject() and inject(): Resolve from the request scope automatically
  • ScopedContainer: Caches REQUEST-scoped instances per scope, disposes lifecycle components on exit

Test plan

  • All 40 existing FastAPI/Flask integration tests pass
  • Linting passes on all changed files (ruff check)
  • Formatting passes (ruff format --check)
  • Pre-commit hooks pass

Fixes #339

Generated with Claude Code

Update example applications to demonstrate Scope.REQUEST usage with a
RequestContext service and /context endpoint. Update READMEs with
request scoping sections showing lifecycle and usage patterns.
@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.85%. Comparing base (9f37e0b) to head (1e8d1c3).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #476   +/-   ##
=======================================
  Coverage   91.85%   91.85%           
=======================================
  Files          21       21           
  Lines        1903     1903           
  Branches      372      372           
=======================================
  Hits         1748     1748           
  Misses         91       91           
  Partials       64       64           
Flag Coverage Δ
python-3.13 91.85% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mikelane mikelane merged commit fb68042 into main Feb 7, 2026
21 checks passed
mikelane added a commit that referenced this pull request Feb 7, 2026
## Summary

- Adds explicit warning to CLAUDE.md Tool Usage section: never use bare
`python`/`python3`, always use `uv run python`
- Documents the `lights-on-uv.sh` AYLO hook that enforces this at the
decision boundary

Bare `python` resolves to system Python which has a stale dioxide
install missing recent features (e.g., `Scope.REQUEST`, `profile`
param). This caused a false positive during PR #476 review.

## Test plan

- [x] Documentation-only change, no code affected
- [x] Pre-commit hooks pass

Fixes #480

Generated with [Claude Code](https://claude.ai/claude-code)

Co-authored-by: Claude Opus 4.6 <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.

Request Scoping: FastAPI and Flask Middleware Integration

1 participant