{"record":{"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/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/docs_src/dependencies/tutorial008d_py310.py#L7-L29","documentation":"Same 404 HTTPException as error 24 but in the non-Annotated tutorial008d_py310.py. The yield-dependency re-raises InternalError; any item_id other than 'plumbus' returns 404.","triggerScenarios":"GET /items/{item_id} with item_id != 'plumbus' and != 'portal-gun'.","commonSituations":"Testing the re-raise variant of yield-dependencies. The 404 fires for ordinary unknown ids; the InternalError (500) fires for 'portal-gun'.","solutions":["Request GET /items/plumbus.","Understand the tutorial's contrast: this variant re-raises InternalError (500) rather than swallowing it.","Map InternalError to an HTTPException in the except block if a clean status code is required."],"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 != \"plumbus\":\n    raise HTTPException(status_code=404, detail=f\"Item '{item_id}' not found\")","handlingStrategy":"try-catch","validationCode":"ALLOWED = {'plumbus'}\nif item_id not in ALLOWED:\n    print('404; portal-gun -> 500')","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('unknown id')\nelif resp.status_code == 500:\n    print('re-raised InternalError')","preventionTips":["Use Annotated form for new code (tutorial008d_an).","Translate InternalError to HTTPException for clean status codes.","Test both failure paths explicitly."],"tags":["fastapi","http-404","dependencies","yield-dependency","re-raise"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}