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


##########
superset/utils/core.py:
##########
@@ -1456,7 +1458,9 @@ def split_adhoc_filters_into_base_filters(  # pylint: 
disable=invalid-name
                     )
             elif expression_type == "SQL":
                 sql_expression = adhoc_filter.get("sqlExpression")
-                sql_expression = sanitize_clause(sql_expression, engine)
+                # keep a trailing line comment from swallowing the " AND " join
+                if sql_expression and "--" in sql_expression:
+                    sql_expression = f"{sql_expression}\n"
                 if clause == "WHERE":

Review Comment:
   **Suggestion:** The new inline-comment handling only detects `--`, so SQL 
filters using other line-comment syntaxes (notably MySQL `# ...`) are still 
concatenated with `AND` on the same line and can comment out the rest of the 
combined predicate. This can silently bypass later filters or generate 
malformed SQL. Extend the normalization to cover engine-specific line comments 
(or use the existing parser-based sanitizer after template rendering) before 
joining clauses. [incorrect condition logic]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ❌ MySQL legacy charts silently ignore additional SQL filters.
   ⚠️ Adhoc filter logic diverges from user expectations with comments.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Configure a dataset whose database uses a MySQL-compatible engine 
(supports "#" line
   comments), and create a legacy viz that uses 
`BaseViz.process_query_filters()` in
   `superset/viz.py:16-22` which calls 
`split_adhoc_filters_into_base_filters()` in
   `superset/utils/core.py:31-71`.
   
   2. In the Explore UI for that legacy chart, add two adhoc SQL filters with
   `clause="WHERE"` into `form_data["adhoc_filters"]` (processed by
   `split_adhoc_filters_into_base_filters()` at 
`superset/utils/core.py:48-69`): the first
   with a trailing "#" comment, e.g. `price > 100 # first filter`, and the 
second a normal
   predicate, e.g. `quantity > 10`.
   
   3. During query preparation, `split_adhoc_filters_into_base_filters()` 
enters the
   `expression_type == "SQL"` branch at `superset/utils/core.py:60-68`; because 
the first
   `sqlExpression` contains "#" but not "--", the newline guard at lines 
1462-1464 is not
   applied, and `form_data["where"]` is built at line 69 as `"(price > 100 # 
first filter)
   AND (quantity > 10)"`, with the " AND " join on the same line after the "#" 
comment.
   
   4. When this WHERE clause is executed against the MySQL-compatible engine, 
everything
   after "#" on that line is treated as a comment, so `AND (quantity > 10)` is 
commented out;
   subsequent validation in `QueryObject._sanitize_filters()` and 
`sanitize_clause()`
   (`superset/common/query_object.py:60-99`, 
`superset/sql/parse.py:15-37,2119-2178`) cannot
   resurrect the commented-out predicate, and the query runs with only the 
first filter
   applied, silently bypassing the second.
   ```
   </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=3aa80acf8d174cef83f45b15c5adaeff&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=3aa80acf8d174cef83f45b15c5adaeff&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/utils/core.py
   **Line:** 1462:1464
   **Comment:**
        *Incorrect Condition Logic: The new inline-comment handling only 
detects `--`, so SQL filters using other line-comment syntaxes (notably MySQL 
`# ...`) are still concatenated with `AND` on the same line and can comment out 
the rest of the combined predicate. This can silently bypass later filters or 
generate malformed SQL. Extend the normalization to cover engine-specific line 
comments (or use the existing parser-based sanitizer after template rendering) 
before joining clauses.
   
   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%2F41996&comment_hash=0a022d9a2a9a18a75bdd7d60775986c060394b19d3cbd440262d0adcd84374e2&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41996&comment_hash=0a022d9a2a9a18a75bdd7d60775986c060394b19d3cbd440262d0adcd84374e2&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