From fb72c2894b922a0504601f0ed4325e83c5cf8324 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Wed, 2 Mar 2022 20:13:18 +0100 Subject: [PATCH] feat(api): custom_metrics support metric_format feat(api): custom_metrics metric_value accept wrong values --- api/schemas.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/schemas.py b/api/schemas.py index 7245dd82a..6c94e2efa 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -778,6 +778,15 @@ class CreateCustomMetricsSchema(CustomMetricChartPayloadSchema): metric_format: Optional[str] = Field(None) # metricFraction: float = Field(None, gt=0, lt=1) + # This is used to handle wrong values sent by the UI + @root_validator(pre=True) + def remove_metric_value(cls, values): + if values.get("metric_type") == MetricType.timeseries \ + or values.get("metric_type") == MetricType.table \ + and values.get("metric_of") != TableMetricOfType.issues: + values["metric_of"] = [] + return values + @root_validator def validator(cls, values): if values.get("metric_type") == MetricType.table: