fix: use sqlalchemy.case() instead of func.case() for conditional aggregation
func.case() is not valid SQLAlchemy - case() must be imported directly from sqlalchemy. This was causing TypeError on /api/v1/admin/background-tasks/tasks/stats. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ Service for monitoring background tasks across the system
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import desc, func
|
||||
from sqlalchemy import case, desc, func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from models.database.marketplace_import_job import MarketplaceImportJob
|
||||
@@ -55,10 +55,10 @@ class BackgroundTasksService:
|
||||
stats = db.query(
|
||||
func.count(MarketplaceImportJob.id).label("total"),
|
||||
func.sum(
|
||||
func.case((MarketplaceImportJob.status == "processing", 1), else_=0)
|
||||
case((MarketplaceImportJob.status == "processing", 1), else_=0)
|
||||
).label("running"),
|
||||
func.sum(
|
||||
func.case(
|
||||
case(
|
||||
(
|
||||
MarketplaceImportJob.status.in_(
|
||||
["completed", "completed_with_errors"]
|
||||
@@ -69,7 +69,7 @@ class BackgroundTasksService:
|
||||
)
|
||||
).label("completed"),
|
||||
func.sum(
|
||||
func.case((MarketplaceImportJob.status == "failed", 1), else_=0)
|
||||
case((MarketplaceImportJob.status == "failed", 1), else_=0)
|
||||
).label("failed"),
|
||||
).first()
|
||||
|
||||
@@ -96,14 +96,14 @@ class BackgroundTasksService:
|
||||
|
||||
stats = db.query(
|
||||
func.count(TestRun.id).label("total"),
|
||||
func.sum(func.case((TestRun.status == "running", 1), else_=0)).label(
|
||||
func.sum(case((TestRun.status == "running", 1), else_=0)).label(
|
||||
"running"
|
||||
),
|
||||
func.sum(func.case((TestRun.status == "passed", 1), else_=0)).label(
|
||||
func.sum(case((TestRun.status == "passed", 1), else_=0)).label(
|
||||
"completed"
|
||||
),
|
||||
func.sum(
|
||||
func.case((TestRun.status.in_(["failed", "error"]), 1), else_=0)
|
||||
case((TestRun.status.in_(["failed", "error"]), 1), else_=0)
|
||||
).label("failed"),
|
||||
func.avg(TestRun.duration_seconds).label("avg_duration"),
|
||||
).first()
|
||||
|
||||
Reference in New Issue
Block a user