invoke-ai/InvokeAI · error · HTTPException
Unexpected error while deleting all except current: {e}
Error message
Unexpected error while deleting all except current: {e} What it means
Thrown by delete_all_except_current: any exception from SessionQueue.delete_all_except_current(queue_id, user_id) is wrapped as a 500 with the cause embedded in the detail. Deletion touches more state than cancellation (rows are removed), so foreign-key or integrity problems in the queue store surface through this handler.
Source
Thrown at invokeai/app/api/routers/session_queue.py:331
@session_queue_router.put(
"/{queue_id}/delete_all_except_current",
operation_id="delete_all_except_current",
responses={200: {"model": DeleteAllExceptCurrentResult}},
)
def delete_all_except_current(
current_user: CurrentUserOrDefault,
queue_id: str = Path(description="The queue id to perform this operation on"),
) -> DeleteAllExceptCurrentResult:
"""Immediately deletes all queue items except in-processing items. Non-admin users can only delete their own items."""
try:
# Admin users can delete all items, non-admin users can only delete their own
user_id = None if current_user.is_admin else current_user.user_id
return ApiDependencies.invoker.services.session_queue.delete_all_except_current(
queue_id=queue_id, user_id=user_id
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Unexpected error while deleting all except current: {e}")
@session_queue_router.put(
"/{queue_id}/cancel_by_batch_ids",
operation_id="cancel_by_batch_ids",
responses={200: {"model": CancelByBatchIDsResult}},
)
def cancel_by_batch_ids(
current_user: CurrentUserOrDefault,
queue_id: str = Path(description="The queue id to perform this operation on"),
batch_ids: list[str] = Body(description="The list of batch_ids to cancel all queue items for", embed=True),
) -> CancelByBatchIDsResult:
"""Immediately cancels all queue items from the given batch ids. Non-admin users can only cancel their own items."""
try:
# Admin users can cancel all items, non-admin users can only cancel their own
user_id = None if current_user.is_admin else current_user.user_id
return ApiDependencies.invoker.services.session_queue.cancel_by_batch_ids(
queue_id=queue_id, batch_ids=batch_ids, user_id=user_idView on GitHub (pinned to 0b6a024f2f)
Solutions
- Read the embedded exception message in detail for the specific DB/service failure
- Pause the processor before bulk-deleting to avoid write contention
- Validate queue_id exists before the call
- Back up and run DB integrity checks / migrations if constraint errors recur
Example fix
// before: delete while processing
await fetch(`/api/v1/queue/${queueId}/delete_all_except_current`, {method: 'PUT'});
// after: pause first, then delete
await fetch(`/api/v1/queue/${queueId}/processor/pause`, {method: 'PUT'});
await fetch(`/api/v1/queue/${queueId}/delete_all_except_current`, {method: 'PUT'}); Defensive patterns
Strategy: try-catch
Validate before calling
const q = await fetch(`/api/v1/queue/${queueId}`);
if (!q.ok) throw new Error(`Queue ${queueId} not found`);
await fetch(`/api/v1/queue/${queueId}/processor/pause`, {method:'PUT'}); // stop writes before delete Type guard
function isDeleteResult(v) { return v !== null && typeof v === 'object' && 'deleted' in v; } Try / catch
try {
const res = await fetch(`/api/v1/queue/${queueId}/delete_all_except_current`, {method:'PUT'});
if (res.status === 500) throw new Error((await res.json()).detail);
return await res.json();
} catch (e) { console.error('bulk delete failed:', e.message); } Prevention
- Pause the processor before deleting to avoid write contention and constraint errors
- Keep the database migrated; orphaned rows cause FK failures on bulk delete
- Back up invokeai.db before large destructive operations
- Treat the embedded detail message as the primary diagnostic
When it happens
Trigger: PUT /{queue_id}/delete_all_except_current with a bad queue_id, DB constraint/foreign-key failure while deleting queue rows, or a service-layer error during bulk delete.
Common situations: Deleting while items are actively being written by the processor (contention); databases with orphaned references from interrupted upgrades; stale queue_id pointing at a nonexistent queue.
Related errors
- Unexpected error while enqueuing batch: {e}
- Unexpected error while listing all queue items: {e}
- Unexpected error while listing all queue item ids: {e}
- Failed to get queue items
- Failed to get queue item summaries
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/9e15606a9a6ed7d0.
Report an issue: GitHub.