diff --git a/src/alerts/alerts_utils.rs b/src/alerts/alerts_utils.rs index 8865c83ff..3b46375d3 100644 --- a/src/alerts/alerts_utils.rs +++ b/src/alerts/alerts_utils.rs @@ -347,7 +347,11 @@ pub fn get_filter_string(where_clause: &Conditions) -> Result { LogicalOperator::And => { let mut exprs = vec![]; for condition in &where_clause.condition_config { - if let Some(value) = &condition.value { + if condition + .value + .as_ref() + .is_some_and(|v| !v.trim().is_empty()) + { // ad-hoc error check in case value is some and operator is either `is null` or `is not null` if condition.operator.eq(&WhereConfigOperator::IsNull) || condition.operator.eq(&WhereConfigOperator::IsNotNull) @@ -355,7 +359,9 @@ pub fn get_filter_string(where_clause: &Conditions) -> Result { return Err("value must be null when operator is either `is null` or `is not null`" .into()); } - let value = NumberOrString::from_string(value.to_owned()); + let value = NumberOrString::from_string( + condition.value.as_ref().unwrap().to_owned(), + ); match value { NumberOrString::Number(val) => exprs.push(format!( "\"{}\" {} {}", @@ -387,7 +393,8 @@ fn match_alert_operator(expr: &ConditionConfig) -> Expr { // the form accepts value as a string // if it can be parsed as a number, then parse it // else keep it as a string - if let Some(value) = &expr.value { + if expr.value.as_ref().is_some_and(|v| !v.trim().is_empty()) { + let value = expr.value.as_ref().unwrap(); let value = NumberOrString::from_string(value.clone()); // for maintaining column case diff --git a/src/alerts/mod.rs b/src/alerts/mod.rs index af1af9387..814d1bb4b 100644 --- a/src/alerts/mod.rs +++ b/src/alerts/mod.rs @@ -343,14 +343,24 @@ impl Conditions { LogicalOperator::And | LogicalOperator::Or => { let expr1 = &self.condition_config[0]; let expr2 = &self.condition_config[1]; - let expr1_msg = if let Some(val) = &expr1.value { - format!("{} {} {}", expr1.column, expr1.operator, val) + let expr1_msg = if expr1.value.as_ref().is_some_and(|v| !v.trim().is_empty()) { + format!( + "{} {} {}", + expr1.column, + expr1.operator, + expr1.value.as_ref().unwrap() + ) } else { format!("{} {}", expr1.column, expr1.operator) }; - let expr2_msg = if let Some(val) = &expr2.value { - format!("{} {} {}", expr2.column, expr2.operator, val) + let expr2_msg = if expr2.value.as_ref().is_some_and(|v| !v.trim().is_empty()) { + format!( + "{} {} {}", + expr2.column, + expr2.operator, + expr2.value.as_ref().unwrap() + ) } else { format!("{} {}", expr2.column, expr2.operator) }; @@ -661,7 +671,12 @@ impl AlertConfig { WhereConfigOperator::IsNull | WhereConfigOperator::IsNotNull ); - if needs_no_value && condition.value.is_some() { + if needs_no_value + && condition + .value + .as_ref() + .is_some_and(|v| !v.trim().is_empty()) + { return Err(AlertError::CustomError( "value must be null when operator is either `is null` or `is not null`" .into(),