diff --git a/backend/app/api/alert_rules.py b/backend/app/api/alert_rules.py index a17ca2bc..419a792e 100644 --- a/backend/app/api/alert_rules.py +++ b/backend/app/api/alert_rules.py @@ -420,8 +420,10 @@ def get_dynamic_thresholds(kpi_id: Optional[int] = None, db: Session = Depends(g query = db.query(DynamicThresholdCache).filter(DynamicThresholdCache.entity_id == entity_id) if kpi_id: query = query.filter(DynamicThresholdCache.kpi_id == kpi_id) - cache = query.order_by(DynamicThresholdCache.id.desc()).limit(50).all() - return {"data": [{c.name: getattr(c, c.name) for c in DynamicThresholdCache.__table__.columns} for c in cache]} + rows = query.order_by(DynamicThresholdCache.id.desc()).limit(50).all() + # 列名取自表元数据,值取自 ORM 行(原实现把 Column 对象当行取值,AttributeError: 'Comparator' object has no attribute 'id') + columns = [col.name for col in DynamicThresholdCache.__table__.columns] + return {"data": [{name: getattr(row, name) for name in columns} for row in rows]} @router.post("/calculate-dynamic")