fix: queue stuck on "Busy" for "Any Model" jobs (#435)

When a print was queued with "Any [Model]", the queue widget only
queried items with printer_id=X after dispatch, missing the next
pending model-based item (printer_id IS NULL, target_model="P1S").
The "Clear Plate & Start Next" button never appeared, leaving the
scheduler stuck reporting "Busy".

Add optional target_model query parameter to GET /queue/. When
combined with printer_id, uses OR logic to also return unassigned
items whose target_model matches. The frontend now passes the
printer's model through PrinterQueueWidget to this query.
This commit is contained in:
maziggy
2026-02-19 14:22:28 +01:00
parent 72d4cea467
commit 5e6c04f303
7 changed files with 31 additions and 10 deletions
+17 -1
View File
@@ -8,7 +8,7 @@ from pathlib import Path
import defusedxml.ElementTree as ET
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy import func, select
from sqlalchemy import and_, func, or_, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
@@ -248,6 +248,9 @@ def _enrich_response(item: PrintQueueItem) -> PrintQueueItemResponse:
async def list_queue(
printer_id: int | None = Query(None, description="Filter by printer (-1 for unassigned)"),
status: str | None = Query(None, description="Filter by status"),
target_model: str | None = Query(
None, description="Filter by target model (also includes model-based items when combined with printer_id)"
),
db: AsyncSession = Depends(get_db),
_: User | None = RequirePermissionIfAuthEnabled(Permission.QUEUE_READ),
):
@@ -267,8 +270,21 @@ async def list_queue(
if printer_id == -1:
# Special value: filter for unassigned items
query = query.where(PrintQueueItem.printer_id.is_(None))
elif target_model:
# Include both printer-specific items AND model-based (unassigned) items
query = query.where(
or_(
PrintQueueItem.printer_id == printer_id,
and_(
PrintQueueItem.printer_id.is_(None),
func.lower(PrintQueueItem.target_model) == target_model.lower(),
),
)
)
else:
query = query.where(PrintQueueItem.printer_id == printer_id)
elif target_model:
query = query.where(func.lower(PrintQueueItem.target_model) == target_model.lower())
if status:
query = query.where(PrintQueueItem.status == status)