{"record":{"id":"061107824f7ddefa","repo":"tiangolo/fastapi","slug":"item-not-found-there-s-only-a-plumbus-here-061107","errorCode":null,"errorMessage":"Item not found, there's only a plumbus here","messagePattern":"Item not found, there's only a plumbus here","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"docs_src/dependencies/tutorial008c_py310.py","lineNumber":24,"sourceCode":"class InternalError(Exception):\n    pass\n\n\ndef get_username():\n    try:\n        yield \"Rick\"\n    except InternalError:\n        print(\"Oops, we didn't raise again, Britney 😱\")\n\n\n@app.get(\"/items/{item_id}\")\ndef get_item(item_id: str, username: str = Depends(get_username)):\n    if item_id == \"portal-gun\":\n        raise InternalError(\n            f\"The portal gun is too dangerous to be owned by {username}\"\n        )\n    if item_id != \"plumbus\":\n        raise HTTPException(\n            status_code=404, detail=\"Item not found, there's only a plumbus here\"\n        )\n    return item_id\n","sourceCodeStart":6,"sourceCodeEnd":28,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/docs_src/dependencies/tutorial008c_py310.py#L6-L28","documentation":"Identical logic to error 22 but in the non-Annotated tutorial008c_py310.py (uses `username: str = Depends(get_username)` instead of Annotated). Same 404 HTTPException for any item_id other than 'plumbus'. The InternalError path for 'portal-gun' is swallowed by the dependency's except block.","triggerScenarios":"GET /items/{item_id} with item_id != 'plumbus' and != 'portal-gun'.","commonSituations":"Same as the Annotated variant; difference is purely the dependency-injection syntax. Hit when clients guess item ids outside the allowed single-element set.","solutions":["Request GET /items/plumbus.","Recognize the tutorial's point: a yield-dependency that catches but does not re-raise will swallow InternalError, so unknown ids simply 404.","Switch to the re-raise pattern (tutorial008d) if you want the InternalError to surface."],"exampleFix":"// before\nif item_id != \"plumbus\":\n    raise HTTPException(status_code=404, detail=\"Item not found, there's only a plumbus here\")\n// after\nif item_id not in (\"plumbus\",):\n    raise HTTPException(status_code=404, detail=\"Item not found, there's only a plumbus here\")","handlingStrategy":"validation","validationCode":"ALLOWED = {'plumbus'}\nassert item_id in ALLOWED","typeGuard":"def is_known_item(item_id: str) -> bool:\n    return item_id == 'plumbus'","tryCatchPattern":"resp = requests.get(f'http://localhost:8000/items/{item_id}')\nif resp.status_code == 404:\n    print('404: only plumbus is valid')","preventionTips":["Use the re-raise variant if you need InternalError to surface.","Keep the allowed-id set documented.","Distinguish swallowed-vs-raised failure modes in tests."],"tags":["fastapi","http-404","dependencies","yield-dependency"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}