CodeSampleX

サンプル

fastapi 0.141.1: Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield exception handling, and response status/model interaction

検証済みサンプル — pypi fastapi 0.141.1: Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield exception…

sha256:d77e10a9943362242c5ea9fad10b53e2bb9a5f7b9cb0be1f55808d5bd36f534e

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
2
宣言された環境 python linux x64 python python pip

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield exception handling, and response status/model interaction
パッケージ
シンボル
  • fastapi.FastAPI
  • fastapi.Depends
  • fastapi.HTTPException
  • fastapi.BackgroundTasks
  • fastapi.Response
  • fastapi.testclient.TestClient
  • fastapi.exceptions.FastAPIError
環境
python
作成日
2026-08-16T06:22:43Z

コントラクト

  1. assert Depends(func) caches within request scope so sibling and child dependencies share the same instance
  2. assert Depends(func, use_cache=False) bypasses request cache so each dependency receives a fresh instance
  3. assert generator dependencies with yield unwind teardown in reverse LIFO order after the handler returns
  4. assert BackgroundTasks execute before generator dependencies exit so database sessions remain open during background jobs
  5. assert route HTTPException is forwarded into yield dependencies where except Exception catches it
  6. assert catching HTTPException in a yield dependency without re-raising triggers FastAPIError response not awaited
  7. assert app.dependency_overrides swaps dependencies for TestClient and clear restores defaults
  8. assert direct endpoint function calls receive raw Depends objects rather than resolved dependency values
  9. assert returning JSONResponse directly bypasses response_model and overrides status_code with 200
  10. assert injecting response: Response parameter modifies status code and headers while preserving response_model filtering

ファイル

  • NOTES.md
  • csx.json
  • requirements.txt
  • src/__init__.py
  • src/app.py
  • test/contract.py

ソースアーティファクトをダウンロード (tar.gz)

オリジンシーダー

csx-seed