{"id":"48a554ee92d6b27f","repo":"tiangolo/fastapi","slug":"item-not-found-there-s-only-a-plumbus-here-48a554","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/tutorial008d_py310.py","lineNumber":25,"sourceCode":"    pass\n\n\ndef get_username():\n    try:\n        yield \"Rick\"\n    except InternalError:\n        print(\"We don't swallow the internal error here, we raise again 😎\")\n        raise\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":7,"sourceCodeEnd":29,"githubUrl":"https://github.com/tiangolo/fastapi/blob/42a41db11f6882807ac3c057b942178d53b97438/docs_src/dependencies/tutorial008d_py310.py#L7-L29","documentation":"Non-Annotated variant of error 26: same 404 \"Item not found, there's only a plumbus here\" with the re-raising yield dependency. Fires for unknown item_ids other than \"portal-gun\".","triggerScenarios":"GET /items/<not-plumbus-and-not-portal-gun> in the tutorial008d_py310 endpoint.","commonSituations":"Unknown resource ids; clients expecting the swallowed-error behavior from 008c now seeing 500s on portal-gun because the dependency re-raises.","solutions":["Call /items/plumbus.","Avoid /items/portal-gun in this variant (InternalError propagates as 500).","Keep 404 detail consistent across Annotated/non-Annotated variants.","Test all three id branches."],"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 != \"plumbus\":\n    raise HTTPException(status_code=404, detail=f\"Item '{item_id}' not found\")","handlingStrategy":"validation","validationCode":"if item_id != \"plumbus\":\n    raise ValueError(\"only plumbus is safe\")","typeGuard":"def is_safe_item(item_id: str) -> bool:\n    return item_id == \"plumbus\"","tryCatchPattern":"r = client.get(f\"/items/{item_id}\")\nif r.status_code == 404:\n    ...\nelif r.status_code >= 500:\n    # re-raised InternalError (e.g. portal-gun)\n    ...","preventionTips":["Avoid portal-gun on this variant.","Validate id before sending.","Handle 5xx distinctly from 404."],"tags":["fastapi","http-404","not-found","dependencies"],"analyzedSha":"42a41db11f6882807ac3c057b942178d53b97438","analyzedAt":"2026-08-04T19:23:32.007Z","schemaVersion":2}