{"record":{"id":"cf6010170774cfb7","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-fetching-counts-by-destinat","errorCode":null,"errorMessage":"Unexpected error while fetching counts by destination: {e}","messagePattern":"Unexpected error while fetching counts by destination: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":664,"sourceCode":"\n@session_queue_router.get(\n    \"/{queue_id}/counts_by_destination\",\n    operation_id=\"counts_by_destination\",\n    responses={200: {\"model\": SessionQueueCountsByDestination}},\n)\ndef counts_by_destination(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to query\"),\n    destination: str = Query(description=\"The destination to query\"),\n) -> SessionQueueCountsByDestination:\n    \"\"\"Gets the counts of queue items by destination. Non-admin users only see their own items.\"\"\"\n    try:\n        user_id = None if current_user.is_admin else current_user.user_id\n        return ApiDependencies.invoker.services.session_queue.get_counts_by_destination(\n            queue_id=queue_id, destination=destination, user_id=user_id\n        )\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while fetching counts by destination: {e}\")\n\n\n@session_queue_router.delete(\n    \"/{queue_id}/d/{destination}\",\n    operation_id=\"delete_by_destination\",\n    responses={200: {\"model\": DeleteByDestinationResult}},\n)\ndef delete_by_destination(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to query\"),\n    destination: str = Path(description=\"The destination to query\"),\n) -> DeleteByDestinationResult:\n    \"\"\"Deletes all items with the given destination. Non-admin users can only delete their own items.\"\"\"\n    try:\n        # Admin users can delete all items, non-admin users can only delete their own\n        user_id = None if current_user.is_admin else current_user.user_id\n        return ApiDependencies.invoker.services.session_queue.delete_by_destination(\n            queue_id=queue_id, destination=destination, user_id=user_id","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L646-L682","documentation":"This HTTP 500 wraps any exception raised while fetching per-destination queue counts. The endpoint computes user scoping (non-admins only see their own counts) and delegates to the session queue service; any service/database failure becomes 'Unexpected error while fetching counts by destination'. It is a server-side failure, not a client input error.","triggerScenarios":"Calling GET /session_queue/{queue_id}/counts_by_destination when the queue service throws — DB outage, invalid queue_id handled upstream as an unexpected exception, or query failure on the counts aggregation.","commonSituations":"Database locked/unavailable; querying counts immediately after a queue was deleted; schema mismatch after an InvokeAI upgrade; aggregations timing out on very large queues.","solutions":["Check server logs for the original exception embedded in the detail","Verify the queue_id exists (use the queue listing endpoint) and the database is reachable","Reduce queue size / archive old completed items if the aggregation times out","Retry after confirming DB health; if reproducible, file a bug with the detail string"],"exampleFix":"// before\nconst counts = await getCountsByDestination(queueId); // unhandled 500\n// after\ntry {\n  const counts = await getCountsByDestination(queueId);\n} catch (e) {\n  if (e.response?.status === 500) {\n    console.error('counts fetch failed:', e.response.data?.detail);\n    return null; // degrade gracefully — counts are non-critical\n  }\n  throw e;\n}","handlingStrategy":"fallback","validationCode":"const queues = await api.get('/session_queue/');\nif (!queues.data.some(q => q.queue_id === queueId)) {\n  console.warn(`Queue ${queueId} unknown; counts request will likely fail`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return (await api.get(`/session_queue/${queueId}/counts_by_destination`)).data;\n} catch (e) {\n  if (e.response?.status === 500) return null; // counts are non-critical\n  throw e;\n}","preventionTips":["Treat count endpoints as optional telemetry — degrade gracefully on 500","Verify queue_id validity before querying counts","Watch server logs for the underlying DB exception","Keep the queue pruned so aggregation queries stay fast"],"tags":["http-500","queue","database","unexpected-error"],"backgroundTag":"internal-server-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}