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


##########
superset/jinja_context.py:
##########
@@ -797,6 +797,28 @@ def get_context(self) -> dict[str, Any]:
         """
         return self._context.copy()
 
+    def has_template(self, sql: str) -> bool:
+        """Whether the SQL contains anything for ``process_template`` to expand
+
+        Lexed rather than parsed, so that a comment -- which leaves no trace in
+        a parsed template -- still counts, and using this processor's own
+        environment, so that any customized delimiters are honored. Lexing
+        evaluates nothing.
+
+        >>> has_template("SELECT '{{ current_username() }}'")
+        True
+        >>> has_template("SELECT '{{1,2},{3,4}}'::int[]")
+        False
+        """
+        try:
+            kinds = {kind for _, kind, _ in self.env.lex(sql)}
+        except TemplateSyntaxError:
+            # Jinja does not recognize this as one of its own constructs, so
+            # there is nothing here it would expand.
+            return False
+
+        return kinds > {"data"}

Review Comment:
   **Suggestion:** The strict superset comparison requires the lexer output to 
contain a `data` token in addition to template tokens. A valid template-only 
SQL such as `{{ 1 }}` or `{{ dataset(1) }}` lexes without `data`, so this 
returns `False`; `QueryEstimationCommand` then sends the raw Jinja to 
`SQLScript` and reports a syntax error instead of refusing the templated query. 
Detect any non-`data` token instead of requiring `data` to be present. 
[incorrect condition logic]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Template-only SQL receives a misleading syntax error.
   - ⚠️ SQL Lab cost estimation rejects the wrong error condition.
   - ⚠️ Valid Jinja queries cannot receive the intended explanation.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d642715ace3a49928b90a6bc4d83914e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d642715ace3a49928b90a6bc4d83914e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/jinja_context.py
   **Line:** 820:820
   **Comment:**
        *Incorrect Condition Logic: The strict superset comparison requires the 
lexer output to contain a `data` token in addition to template tokens. A valid 
template-only SQL such as `{{ 1 }}` or `{{ dataset(1) }}` lexes without `data`, 
so this returns `False`; `QueryEstimationCommand` then sends the raw Jinja to 
`SQLScript` and reports a syntax error instead of refusing the templated query. 
Detect any non-`data` token instead of requiring `data` to be present.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42785&comment_hash=9a651622497fa871e1bdf117a94d80f3def12c4f5b3bdc6a039c4a6247846bba&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42785&comment_hash=9a651622497fa871e1bdf117a94d80f3def12c4f5b3bdc6a039c4a6247846bba&reaction=dislike'>👎</a>



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