Sample
fastapi 0.141.1: Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield exception handling, and response status/model interaction
Verified sample for pypi fastapi 0.141.1: Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield…
sha256:d77e10a9943362242c5ea9fad10b53e2bb9a5f7b9cb0be1f55808d5bd36f534e
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
python linux x64 python python pip
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-16 |
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-18 |
Case
HOW- Goal
- Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield exception handling, and response status/model interaction
- Symbols
-
- fastapi.FastAPI
- fastapi.Depends
- fastapi.HTTPException
- fastapi.BackgroundTasks
- fastapi.Response
- fastapi.testclient.TestClient
- fastapi.exceptions.FastAPIError
- Environment
- python
- Created
- 2026-08-16T06:22:43Z
Contract
- assert Depends(func) caches within request scope so sibling and child dependencies share the same instance
- assert Depends(func, use_cache=False) bypasses request cache so each dependency receives a fresh instance
- assert generator dependencies with yield unwind teardown in reverse LIFO order after the handler returns
- assert BackgroundTasks execute before generator dependencies exit so database sessions remain open during background jobs
- assert route HTTPException is forwarded into yield dependencies where except Exception catches it
- assert catching HTTPException in a yield dependency without re-raising triggers FastAPIError response not awaited
- assert app.dependency_overrides swaps dependencies for TestClient and clear restores defaults
- assert direct endpoint function calls receive raw Depends objects rather than resolved dependency values
- assert returning JSONResponse directly bypasses response_model and overrides status_code with 200
- assert injecting response: Response parameter modifies status code and headers while preserving response_model filtering
Files
- NOTES.md
- csx.json
- requirements.txt
- src/__init__.py
- src/app.py
- test/contract.py