[fix] Use cursor.description to detect result-returning queries#75
[fix] Use cursor.description to detect result-returning queries#75jonasbrami wants to merge 1 commit into
Conversation
Replace brittle sql_upper.startswith() keyword check with cursor.description, which reliably detects any statement that returns a result set (SELECT, SHOW, DESCRIBE, EXPLAIN, CTEs, etc.) without maintaining a hardcoded list of SQL keywords.
|
Blocking: missing regression tests. This classification branch has already caused Issue #62 Bug 5 once, and the cases motivating this PR (leading comments, parenthesized Please add regression tests covering at least:
|
catpineapple
left a comment
There was a problem hiding this comment.
Thank you for your contribution, but some additional test cases are needed to ensure the robustness of doris MCP.
* [fix] Use cursor.description to detect result-returning queries Replace brittle sql_upper.startswith() keyword check with cursor.description, which reliably detects any statement that returns a result set (SELECT, SHOW, DESCRIBE, EXPLAIN, CTEs, etc.) without maintaining a hardcoded list of SQL keywords. * Fix max_rows bypass for comment-prefixed SELECT in execute_sql_for_mcp Same root cause as #75: sql.upper().startswith("SELECT") at query_executor.py:689 returns False when SQL begins with a leading '--' or '/* */' comment, so the auto-injected LIMIT {max_rows} is silently skipped and large queries can be dispatched unbounded. This callsite runs before cursor.execute, so cursor.description is not available. Use a small helper that strips leading SQL comments before extracting the first keyword. * Add regression tests for result-set detection contract These tests pin the user-facing contract of DorisConnection.execute(): any SQL the driver reports as producing a result set must return its rows, regardless of how the statement is phrased. Guards against regression of: - Issue #62 Bug 5 (CTE / WITH returning empty data) - The leading-comment bug fixed in #75 (data: [] with row_count > 0 for SELECT prefixed by '--' or '/* */') - The same-root-cause LIMIT bypass fixed in the previous commit Also adds unit tests for the new get_first_sql_keyword helper. --------- Co-authored-by: jonas.brami <jonasbrami@gmail.com>
|
Hi @jonasbrami, heads up — #87 has been merged. It preserves your commit as-is at the base of the branch (so you remain the author of the The underlying bug is now fixed on master, so this PR can be closed at your convenience. Thanks for the original fix! |
Replace brittle sql_upper.startswith() keyword check with cursor.description, which reliably detects any statement that returns a result set (SELECT, SHOW, DESCRIBE, EXPLAIN, CTEs, etc.) without maintaining a hardcoded list of SQL keywords.