{"record":{"id":"f399096faee9061c","repo":"tiangolo/fastapi","slug":"item-not-found-f39909","errorCode":null,"errorMessage":"Item not found","messagePattern":"Item not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"docs_src/bigger_applications/app_an_py310/routers/items.py","lineNumber":24,"sourceCode":"    prefix=\"/items\",\n    tags=[\"items\"],\n    dependencies=[Depends(get_token_header)],\n    responses={404: {\"description\": \"Not found\"}},\n)\n\n\nfake_items_db = {\"plumbus\": {\"name\": \"Plumbus\"}, \"gun\": {\"name\": \"Portal Gun\"}}\n\n\n@router.get(\"/\")\nasync def read_items():\n    return fake_items_db\n\n\n@router.get(\"/{item_id}\")\nasync def read_item(item_id: str):\n    if item_id not in fake_items_db:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    return {\"name\": fake_items_db[item_id][\"name\"], \"item_id\": item_id}\n\n\n@router.put(\n    \"/{item_id}\",\n    tags=[\"custom\"],\n    responses={403: {\"description\": \"Operation forbidden\"}},\n)\nasync def update_item(item_id: str):\n    if item_id != \"plumbus\":\n        raise HTTPException(\n            status_code=403, detail=\"You can only update the item: plumbus\"\n        )\n    return {\"item_id\": item_id, \"name\": \"The great Plumbus\"}\n","sourceCodeStart":6,"sourceCodeEnd":39,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/docs_src/bigger_applications/app_an_py310/routers/items.py#L6-L39","documentation":"Raised (404) by GET /items/{item_id} on the items router when item_id is not in fake_items_db, which is seeded with only 'plumbus' and 'gun'. The router already declares responses={404: {...}} so this is the documented not-found path. Note the X-Token dependency has already passed by this point.","triggerScenarios":"GET /items/plumbus or /items/gun succeed; any other id (e.g. /items/foo) with a valid X-Token yields this 404.","commonSituations":"Confusing this router's seed data ({plumbus, gun}) with the app_testing seed ({foo, bar}); typos; expecting an item created elsewhere.","solutions":["GET /items/plumbus or /items/gun.","Confirm you are hitting the bigger-applications app, not the app_testing one (different seed sets).","Add the missing id to fake_items_db if testing a read path."],"exampleFix":"// before\nGET /items/foo\n// after\nGET /items/plumbus","handlingStrategy":"try-catch","validationCode":"import httpx\nKNOWN = {'plumbus', 'gun'}\nitem_id = 'plumbus'\nif item_id in KNOWN:\n    resp = httpx.get(f'http://localhost:8000/items/{item_id}', headers={'X-Token': 'fake-super-secret-token'})","typeGuard":"def is_known_router_item(item_id: object) -> bool:\n    return isinstance(item_id, str) and item_id in {'plumbus', 'gun'}","tryCatchPattern":"try:\n    resp = httpx.get(url, headers=headers)\n    resp.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 404:\n        ...","preventionTips":["Remember the seed set here differs from other tutorials.","Whitelist known ids before GET.","Confirm which app you are calling."],"tags":["fastapi","not-found","in-memory-store","httpexception","bigger-applications"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}