{"record":{"id":"b354f78c3ca897d9","repo":"tiangolo/fastapi","slug":"item-not-found-b354f7","errorCode":null,"errorMessage":"Item not found","messagePattern":"Item not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"docs_src/dependencies/tutorial008b_an_py310.py","lineNumber":28,"sourceCode":"    \"portal-gun\": {\"description\": \"Gun to create portals\", \"owner\": \"Rick\"},\n}\n\n\nclass OwnerError(Exception):\n    pass\n\n\ndef get_username():\n    try:\n        yield \"Rick\"\n    except OwnerError as e:\n        raise HTTPException(status_code=400, detail=f\"Owner error: {e}\")\n\n\n@app.get(\"/items/{item_id}\")\ndef get_item(item_id: str, username: Annotated[str, Depends(get_username)]):\n    if item_id not in data:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    item = data[item_id]\n    if item[\"owner\"] != username:\n        raise OwnerError(username)\n    return item\n","sourceCodeStart":10,"sourceCodeEnd":33,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/docs_src/dependencies/tutorial008b_an_py310.py#L10-L33","documentation":"Raised (404) by GET /items/{item_id} in tutorial008b when item_id is not a key in the data dict ('plumbus' or 'portal-gun'). This check runs after the get_username dependency has already yielded, so the dependency's username is available but the resource simply does not exist.","triggerScenarios":"GET /items/<anything-but-plumbus-or-portal-gun>. Note 'plumbus' will pass this check but then fail the owner check (error 18); 'portal-gun' succeeds fully.","commonSituations":"Confusing this file's seed set ({plumbus, portal-gun}) with other tutorials' seeds; typos; expecting cross-process persistence.","solutions":["GET /items/portal-gun for a fully successful read.","GET /items/plumbus only if you also expect/handle the owner-error 400.","Confirm you are reading the tutorial008b data set, not another file's."],"exampleFix":"// before\nGET /items/foo\n// after\nGET /items/portal-gun","handlingStrategy":"try-catch","validationCode":"import httpx\nKNOWN = {'plumbus', 'portal-gun'}\nitem_id = 'portal-gun'\nif item_id in KNOWN:\n    resp = httpx.get(f'http://localhost:8000/items/{item_id}')","typeGuard":"def is_known_tutorial008b_item(item_id: object) -> bool:\n    return isinstance(item_id, str) and item_id in {'plumbus', 'portal-gun'}","tryCatchPattern":"try:\n    resp = httpx.get(f'http://localhost:8000/items/{item_id}')\n    resp.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 404:\n        # item does not exist\n        ...","preventionTips":["Use only the ids present in this file's data dict.","Note 'plumbus' exists but will then fail the owner check.","Whitelist ids before requesting."],"tags":["fastapi","not-found","in-memory-store","httpexception","dependencies-tutorial"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}