{"record":{"id":"73014c7c231d739c","repo":"invoke-ai/InvokeAI","slug":"no-queue-item-with-id-item-id","errorCode":null,"errorMessage":"No queue item with id {item_id}","messagePattern":"No queue item with id (.+?)","errorType":"exception","errorClass":"SessionQueueItemNotFoundError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/session_queue/session_queue_sqlite.py","lineNumber":529,"sourceCode":"        the SQL: the guard is a Python check between the SELECT and the UPDATE, valid only while\n        every writer goes through that lock. When no transition happens, the item is returned\n        unchanged and no status-changed event is emitted; a vanished row raises\n        SessionQueueItemNotFoundError.\n        \"\"\"\n        if queue_item is not None and queue_item.item_id != item_id:\n            raise ValueError(f\"Queue item {queue_item.item_id} does not match requested item {item_id}\")\n\n        updated_status_row: sqlite3.Row | None = None\n        with self._db.transaction() as cursor:\n            cursor.execute(\n                \"\"\"--sql\n                SELECT status FROM session_queue WHERE item_id = ?\n                \"\"\",\n                (item_id,),\n            )\n            row = cursor.fetchone()\n            if row is None:\n                raise SessionQueueItemNotFoundError(f\"No queue item with id {item_id}\")\n            current_status = row[0]\n\n            # Only update if not already finished (completed, failed or canceled).\n            if current_status not in (\"completed\", \"failed\", \"canceled\"):\n                cursor.execute(\n                    \"\"\"--sql\n                    UPDATE session_queue\n                    SET status = ?, status_sequence = COALESCE(status_sequence, 0) + 1, error_type = ?, error_message = ?, error_traceback = ?, device = COALESCE(?, device)\n                    WHERE item_id = ?\n                    \"\"\",\n                    (status, error_type, error_message, error_traceback, device, item_id),\n                )\n                cursor.execute(\n                    \"\"\"--sql\n                    SELECT\n                        status,\n                        status_sequence,\n                        error_type,","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/session_queue/session_queue_sqlite.py#L511-L547","documentation":"_transition_queue_item_status reads the current status of a queue item before updating it; if no row exists for the given item_id, SessionQueueItemNotFoundError is raised. This protects status transitions (including cancellation sweeps) from acting on nonexistent or already-deleted items.","triggerScenarios":"Calling _set_queue_item_status or _cancel_in_progress_matching with an item_id that was deleted (e.g. by delete_queue_item in another request/worker) or never existed, against the SQLite session queue.","commonSituations":"Race between canceling/deleting a queue item from the UI while a processor thread transitions its status; passing a stale item_id cached client-side; double-deletion handling.","solutions":["Catch SessionQueueItemNotFoundError and treat the item as already gone (idempotent handling)","Fetch a fresh queue item list before transitioning instead of using cached ids","Check for concurrent delete/cancel operations in your automation scripts","If it recurs, inspect the SQLite session_queue table for the item_id"],"exampleFix":"// before\nservices.session_queue._set_queue_item_status(item_id, \"canceled\")\n// after\ntry:\n    services.session_queue._set_queue_item_status(item_id, \"canceled\")\nexcept SessionQueueItemNotFoundError:\n    pass  # item already deleted","handlingStrategy":"try-catch","validationCode":"def queue_item_exists(services, item_id: int) -> bool:\n    try:\n        services.session_queue.get_queue_item(item_id)\n        return True\n    except SessionQueueItemNotFoundError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    services.session_queue._set_queue_item_status(item_id, status)\nexcept SessionQueueItemNotFoundError:\n    logger.info(\"Queue item %s already deleted; skipping transition.\", item_id)","preventionTips":["Treat item deletion as making subsequent transitions no-ops (idempotent handlers)","Re-fetch queue items instead of caching ids across operations","Avoid deleting queue items from another thread/worker while processors run","Verify the item_id against list_queue_items before transitioning"],"tags":["queue","sqlite","not-found"],"backgroundTag":"queue-item-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}