codeant-ai-for-open-source[bot] commented on code in PR #42014: URL: https://github.com/apache/superset/pull/42014#discussion_r3574723994
########## superset/mcp_service/sql_lab/tool/execute_sql.py: ########## @@ -55,6 +55,52 @@ logger = logging.getLogger(__name__) +async def _validate_non_destructive_sql( + request: ExecuteSqlRequest, + ctx: Context, + database: Any, + sql_preview: str, +) -> ExecuteSqlResponse | None: + """Return an error response when SQL cannot safely be executed.""" + with event_logger.log_context(action="mcp.execute_sql.ddl_check"): + try: + sql_to_check = request.sql Review Comment: **Suggestion:** Add a concrete type annotation for this local SQL string variable in the new helper function. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> The helper introduces a local string variable that is clearly annotatable, but the file leaves it untyped. This matches the custom rule requiring type hints on relevant Python variables. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b286f41ed13c4987a17b4a4d5d0e7713&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b286f41ed13c4987a17b4a4d5d0e7713&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/mcp_service/sql_lab/tool/execute_sql.py **Line:** 67:67 **Comment:** *Custom Rule: Add a concrete type annotation for this local SQL string variable in the new helper function. 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%2F42014&comment_hash=967faf10d9777e2d48ee6889db71204d83f0808f32b934c0912bbb3707203bca&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42014&comment_hash=967faf10d9777e2d48ee6889db71204d83f0808f32b934c0912bbb3707203bca&reaction=dislike'>๐</a> ########## superset/mcp_service/sql_lab/tool/execute_sql.py: ########## @@ -122,44 +168,11 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: Context) -> ExecuteSqlRes # Fail-closed: if parsing fails, block the query rather than # allowing potentially destructive SQL to bypass the check. # Render Jinja2 templates first so templated SQL can be parsed. - with event_logger.log_context(action="mcp.execute_sql.ddl_check"): - try: - sql_to_check = request.sql - if request.template_params: - from superset.jinja_context import get_template_processor - - tp = get_template_processor(database=database) - sql_to_check = tp.process_template( - request.sql, **request.template_params - ) - - script = SQLScript(sql_to_check, database.db_engine_spec.engine) - if script.has_destructive(): - await ctx.error( - "Destructive DDL blocked: sql_preview=%r" % sql_preview - ) - return ExecuteSqlResponse( - success=False, - error=( - "Destructive DDL statements (DROP, TRUNCATE, ALTER) " - "are not allowed through MCP. Use the Superset SQL " - "Lab UI for administrative database operations." - ), - error_type=SupersetErrorType.DML_NOT_ALLOWED_ERROR.value, - ) - except Exception as parse_err: - await ctx.error( - "DDL pre-check failed to parse SQL, blocking query: %s" - % str(parse_err) - ) - return ExecuteSqlResponse( - success=False, - error=( - "SQL could not be parsed for security validation. " - "Please check your SQL syntax and try again." - ), - error_type=SupersetErrorType.INVALID_SQL_ERROR.value, - ) + validation_error = await _validate_non_destructive_sql( + request, ctx, database, sql_preview + ) Review Comment: **Suggestion:** Add an explicit type annotation for this newly introduced local variable to comply with the type-hint requirement for relevant variables. [custom_rule] **Severity Level:** Minor ๐งน <details> <summary><b>Why it matters? โญ </b></summary> The new local variable is assigned the result of a function that returns ExecuteSqlResponse | None, so it can and should be annotated to satisfy the Python type-hint rule for relevant variables. </details> <details> <summary><b>Rule source ๐ </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=34d28bf1af2e42e5bd47f7b483b84eb1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=34d28bf1af2e42e5bd47f7b483b84eb1&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/mcp_service/sql_lab/tool/execute_sql.py **Line:** 171:173 **Comment:** *Custom Rule: Add an explicit type annotation for this newly introduced local variable to comply with the type-hint requirement for relevant variables. 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%2F42014&comment_hash=f8d8fb7ad6a96e58ed71206e53c92c83b418742a91598e1f404ddafebd1ac1fe&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42014&comment_hash=f8d8fb7ad6a96e58ed71206e53c92c83b418742a91598e1f404ddafebd1ac1fe&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]
