codeant-ai-for-open-source[bot] commented on code in PR #42929:
URL: https://github.com/apache/superset/pull/42929#discussion_r3763264557


##########
superset/commands/report/base.py:
##########
@@ -58,6 +68,52 @@ def run(self) -> Any:
     def validate(self) -> None:
         pass
 
+    def validate_alert_query(
+        self,
+        database: Database,
+        sql: str,
+        exceptions: list[ValidationError],
+    ) -> None:
+        """
+        Validate alert SQL at save time: it must parse as a single statement,
+        must not mutate state unless the database allows DML, and the saving
+        user must be authorized for the tables it reads. Templated SQL that
+        only parses after rendering is validated at execution time on the
+        rendered query.
+        """
+        contains_jinja = bool(_JINJA_BLOCK_RE.search(sql))
+        try:
+            script = SQLScript(sql, engine=database.backend)
+        except SupersetParseError as ex:
+            if not contains_jinja:
+                exceptions.append(
+                    ValidationError(
+                        _("Invalid SQL: %(error)s", error=ex.error.message),
+                        field_name="sql",
+                    )
+                )
+            return
+        if len(script.statements) != 1:
+            exceptions.append(AlertQueryMultipleStatementsValidationError())

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > For templated SQL that parses successfully, retain save-time 
statement-count, DML, and access validation; only defer validation when parsing 
fails due to unresolved Jinja.
   
   **Applied to:**
     - `superset/commands/report/base.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to