{"record":{"id":"df75f545e40b3f8f","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-fetching-queue-item-e","errorCode":null,"errorMessage":"Unexpected error while fetching queue item: {e}","messagePattern":"Unexpected error while fetching queue item: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":579,"sourceCode":"    },\n    response_model_exclude_none=True,\n)\ndef get_queue_item(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n    item_id: int = Path(description=\"The queue item to get\"),\n) -> SessionQueueItem:\n    \"\"\"Gets a queue item\"\"\"\n    try:\n        queue_item = ApiDependencies.invoker.services.session_queue.get_queue_item(item_id=item_id)\n        if queue_item.queue_id != queue_id:\n            raise HTTPException(status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\")\n        # Sanitize item for non-admin users\n        return sanitize_queue_item_for_user(queue_item, current_user.user_id, current_user.is_admin)\n    except SessionQueueItemNotFoundError:\n        raise HTTPException(status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\")\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while fetching queue item: {e}\")\n\n\n@session_queue_router.delete(\n    \"/{queue_id}/i/{item_id}\",\n    operation_id=\"delete_queue_item\",\n)\ndef delete_queue_item(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n    item_id: int = Path(description=\"The queue item to delete\"),\n) -> None:\n    \"\"\"Deletes a queue item. Users can only delete their own items unless they are an admin.\"\"\"\n    try:\n        # Get the queue item to check ownership\n        queue_item = ApiDependencies.invoker.services.session_queue.get_queue_item(item_id)\n        if queue_item.queue_id != queue_id:\n            raise HTTPException(status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\")\n","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L561-L597","documentation":"HTTPException(500) raised as the catch-all in GET /session_queue/{queue_id}/i/{item_id} when any exception other than the queue-id mismatch or SessionQueueItemNotFoundError occurs while fetching or sanitizing the item. This includes sanitize_queue_item_for_user failures and service/storage errors.","triggerScenarios":"Calling GET /api/v1/session_queue/{queue_id}/i/{item_id} when the underlying get_queue_item service call throws a non-not-found error (DB failure), or sanitize_queue_item_for_user raises while stripping data for a non-admin user (e.g. malformed session graph JSON stored on the item).","commonSituations":"Corrupted queue item row whose session/graph payload fails to deserialize; database outage; a non-admin user requesting an item whose stored graph trips the sanitization code.","solutions":["Inspect the interpolated {e} in the response detail and server logs to find the failing step","If sanitization/graph deserialization is the cause, delete the corrupted queue item via the queue UI/API and re-run the generation","Check database health and re-run migrations after upgrades","Retry after a transient DB error is resolved"],"exampleFix":"// before: 500 on malformed stored graph\nGET /api/v1/session_queue/q1/i/42\n// after: catch and fall back to listing items\ntry { return await getItem(queueId, itemId) }\ncatch (e) { log.warn(e); return (await listItems(queueId)).find(i => i.item_id === itemId) ?? null }","handlingStrategy":"fallback","validationCode":"// fall back to listing if direct fetch returns 500\ntry { return await api.get(`/api/v1/session_queue/${queueId}/i/${itemId}`) }\ncatch { /* handled below */ }","typeGuard":"function isWellFormedQueueItem(item) {\n  return item != null && typeof item.item_id === 'number' && item.session != null\n}","tryCatchPattern":"try {\n  return await api.get(`/api/v1/session_queue/${queueId}/i/${itemId}`)\n} catch (e) {\n  if (e.response?.status === 500) {\n    log.error('Queue item fetch failed:', e.response.data?.detail)\n    return (await api.get(`/api/v1/session_queue/${queueId}/items`)).data.items.find(i => i.item_id === itemId) ?? null\n  }\n  throw e\n}","preventionTips":["Check server logs for graph/serialization errors on stored queue items","Delete and re-enqueue corrupted items rather than retrying them","Keep DB healthy and upgraded to the schema matching your InvokeAI version"],"tags":["fastapi","http-500","queue","data-corruption"],"backgroundTag":"unexpected-internal-server-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}