{"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/42a41db11f6882807ac3c057b942178d53b97438/docs_src/dependencies/tutorial008c_py310.py#L6-L28","documentation":"Same 404 \"Item not found, there's only a plumbus here\" as error 24, in the non-Annotated Depends style. Raised when item_id is not \"plumbus\" and not \"portal-gun\".","triggerScenarios":"GET /items/<not-plumbus-and-not-portal-gun> using the default-value Depends form of the endpoint.","commonSituations":"Same as error 24; encountered when the older tutorial variant is in use.","solutions":["Call /items/plumbus.","Document the allowed id set and validate input early.","Keep 404 detail text consistent across endpoints.","Test the negative path."],"exampleFix":"# before\nif item_id != \"plumbus\":\n    raise HTTPException(status_code=404, detail=\"Item not found, there's only a plumbus here\")\n\n# after\nif item_id not in {\"plumbus\"}:\n    raise HTTPException(status_code=404, detail=f\"Unknown item '{item_id}'\")","handlingStrategy":"validation","validationCode":"if item_id not in {\"plumbus\", \"portal-gun\"}:\n    raise ValueError(\"unsupported item id\")","typeGuard":"def is_known_item(item_id: str) -> bool:\n    return item_id in {\"plumbus\", \"portal-gun\"}","tryCatchPattern":"r = client.get(f\"/items/{item_id}\")\nif r.status_code == 404:\n    ...","preventionTips":["Validate the id client-side before calling.","Treat the whimsical 404 detail as informative, not authoritative.","Keep Annotated/non-Annotated endpoints behaviorally identical."],"tags":["fastapi","http-404","not-found","dependencies"],"analyzedSha":"42a41db11f6882807ac3c057b942178d53b97438","analyzedAt":"2026-08-04T19:23:32.007Z","schemaVersion":2}