invoke-ai/InvokeAI · error · HTTPException
Unexpected error while fetching counts by destination: {e}
Error message
Unexpected error while fetching counts by destination: {e} What it means
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.
Source
Thrown at invokeai/app/api/routers/session_queue.py:664
@session_queue_router.get(
"/{queue_id}/counts_by_destination",
operation_id="counts_by_destination",
responses={200: {"model": SessionQueueCountsByDestination}},
)
def counts_by_destination(
current_user: CurrentUserOrDefault,
queue_id: str = Path(description="The queue id to query"),
destination: str = Query(description="The destination to query"),
) -> SessionQueueCountsByDestination:
"""Gets the counts of queue items by destination. Non-admin users only see their own items."""
try:
user_id = None if current_user.is_admin else current_user.user_id
return ApiDependencies.invoker.services.session_queue.get_counts_by_destination(
queue_id=queue_id, destination=destination, user_id=user_id
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Unexpected error while fetching counts by destination: {e}")
@session_queue_router.delete(
"/{queue_id}/d/{destination}",
operation_id="delete_by_destination",
responses={200: {"model": DeleteByDestinationResult}},
)
def delete_by_destination(
current_user: CurrentUserOrDefault,
queue_id: str = Path(description="The queue id to query"),
destination: str = Path(description="The destination to query"),
) -> DeleteByDestinationResult:
"""Deletes all items with the given destination. 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_by_destination(
queue_id=queue_id, destination=destination, user_id=user_idView on GitHub (pinned to 0b6a024f2f)
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
Example fix
// before
const counts = await getCountsByDestination(queueId); // unhandled 500
// after
try {
const counts = await getCountsByDestination(queueId);
} catch (e) {
if (e.response?.status === 500) {
console.error('counts fetch failed:', e.response.data?.detail);
return null; // degrade gracefully — counts are non-critical
}
throw e;
} Defensive patterns
Strategy: fallback
Validate before calling
const queues = await api.get('/session_queue/');
if (!queues.data.some(q => q.queue_id === queueId)) {
console.warn(`Queue ${queueId} unknown; counts request will likely fail`);
} Try / catch
try {
return (await api.get(`/session_queue/${queueId}/counts_by_destination`)).data;
} catch (e) {
if (e.response?.status === 500) return null; // counts are non-critical
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Database locked/unavailable; querying counts immediately after a queue was deleted; schema mismatch after an InvokeAI upgrade; aggregations timing out on very large queues.
Related errors
- Unexpected error while canceling queue item: {e}
- Unexpected error while deleting by destination: {e}
- Unexpected error while canceling by batch id: {e}
- Unexpected error while canceling by destination: {e}
- Unexpected error while clearing queue: {e}
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/cf6010170774cfb7.
Report an issue: GitHub.