{"record":{"id":"aabef8d29ca1dce6","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-deleting-by-destination-e","errorCode":null,"errorMessage":"Unexpected error while deleting by destination: {e}","messagePattern":"Unexpected error while deleting by destination: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":685,"sourceCode":"@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\n        )\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while deleting by destination: {e}\")\n","sourceCodeStart":667,"sourceCodeEnd":686,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L667-L686","documentation":"This HTTP 500 wraps any exception from delete_by_destination, which removes all queued items for a destination (all of them for admins, only the caller's own for non-admins). Any non-HTTPException failure in the service layer — typically database errors — is reported as 'Unexpected error while deleting by destination'. The delete may be partially applied, so queue state should be re-fetched.","triggerScenarios":"Calling DELETE /session_queue/{queue_id}/d/{destination} when the bulk delete throws: DB failure, lock contention with concurrent enqueue/cancel, or an invalid state in the queue service.","commonSituations":"SQLite database locked by another process (e.g. during long-running generations); deleting a destination while items are actively being processed; post-upgrade schema mismatch.","solutions":["Inspect server logs for the underlying exception in the response detail","Verify database health and re-run the delete after transient lock contention clears","Re-fetch the queue listing to confirm which items actually remain before retrying","Avoid bulk-deleting while generations are actively consuming the same queue"],"exampleFix":"// before\nawait deleteByDestination(queueId, destination); // unhandled 500, partial state possible\n// after\ntry {\n  await deleteByDestination(queueId, destination);\n} catch (e) {\n  if (e.response?.status === 500) {\n    const remaining = await listQueueItems(queueId);\n    console.warn('delete failed, remaining items:', remaining.length);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const items = await api.get(`/session_queue/${queueId}/i`);\nconst count = items.data.items.filter(i => i.destination === destination).length;\nif (count === 0) return { deleted: 0 }; // nothing to delete — skip risky bulk call","typeGuard":null,"tryCatchPattern":"try {\n  await api.delete(`/session_queue/${queueId}/d/${destination}`);\n} catch (e) {\n  if (e.response?.status === 500) {\n    const remaining = await api.get(`/session_queue/${queueId}/i`);\n    console.error('Bulk delete failed; items remaining:', remaining.data.items.length);\n  }\n  throw e;\n}","preventionTips":["Avoid bulk deletes while generations are actively running on the queue","After a 500, re-list the queue to see the actual (possibly partial) state","Keep the DB un-locked (no competing processes holding SQLite)","Wrap bulk operations with verification of the resulting item count"],"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"}