bkyryliuk commented on a change in pull request #10605:
URL:
https://github.com/apache/incubator-superset/pull/10605#discussion_r479565329
##########
File path: superset/views/alerts.py
##########
@@ -23,17 +24,61 @@
from wtforms import BooleanField, Form, StringField
from superset.constants import RouteMethod
-from superset.models.alerts import Alert, AlertLog
+from superset.models.alerts import (
+ Alert,
+ AlertLog,
+ AlertValidatorType,
+ SQLObservation,
+ SQLObserver,
+ Validator,
+)
from superset.models.schedules import ScheduleType
from superset.tasks.schedules import schedule_alert_query
+from superset.utils import core as utils
from superset.utils.core import get_email_address_str, markdown
from ..exceptions import SupersetException
+from ..sql_parse import ParsedQuery
+from ..tasks.alerts.oberver import check_observer_result
from .base import SupersetModelView
# TODO: access control rules for this module
+def check_observer_sql(item: "SQLObserverInlineView") -> None:
+ try:
+ parsed_query = ParsedQuery(item.sql)
+ sql = parsed_query.stripped()
+ df = item.database.get_df(sql)
+
+ error_msg = check_observer_result(df, item.id, item.name)
+
+ if error_msg:
+ raise SupersetException(f"Error: {error_msg}")
+
+ except Exception as ex: # pylint: disable=broad-except
+ raise SupersetException(f"Observer raised exception: {ex}")
+
+
+def check_validator_config(item: "ValidatorInlineView") -> None:
Review comment:
this should live in the alerts module next to the validator
implementations
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]