Skip to content

refactor(mysql): strip trailing semicolon on unlimited query path for connector consistency - #2595

Merged
goldmedal merged 2 commits into
Canner:mainfrom
Bartok9:fix/mysql-strip-semicolon-unlimited
Jul 28, 2026
Merged

refactor(mysql): strip trailing semicolon on unlimited query path for connector consistency#2595
goldmedal merged 2 commits into
Canner:mainfrom
Bartok9:fix/mysql-strip-semicolon-unlimited

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Strip trailing semicolons on MySQL unlimited queries.

Motivation

LIMIT and EXPLAIN already stripped; unlimited left terminators intact.

Verification

.venv/bin/python -m pytest tests/unit/test_mysql_semicolon_unlimited.py -q
2 passed

Summary by CodeRabbit

  • Bug Fixes

    • Improved MySQL query handling by stripping trailing semicolons from unlimited queries before execution.
    • Kept the existing limited-query behavior, ensuring queries remain clean and still include LIMIT when specified.
  • Tests

    • Added unit tests covering semicolon removal for both unlimited and limited query paths.

Match LIMIT and EXPLAIN composition when no limit is applied.
@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

MySQL query terminator normalization

Layer / File(s) Summary
Normalize and test query terminators
core/wren/src/wren/connector/mysql.py, core/wren/tests/unit/test_mysql_semicolon_unlimited.py
MySqlConnector.query strips trailing semicolons when no limit is provided. Unit tests verify semicolon-free unlimited execution and limited-path behavior with LIMIT 2.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • Canner/WrenAI#2557: Modifies MySqlConnector.query to strip semicolons on unlimited queries and adds corresponding tests.
  • Canner/WrenAI#2593: Adds MySQL unlimited-path semicolon stripping and semicolon-free SQL assertions.
  • Canner/WrenAI#2594: Applies the same unlimited query-path normalization pattern to another connector with tests.

Suggested reviewers: goldmedal

Poem

A bunny hops through SQL bright,
Trims semicolons left and right.
Unlimited queries now run clean,
Limited ones keep LIMIT keen.
Tests cheer at execution night!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: stripping trailing semicolons on the unlimited MySQL query path for consistency.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@goldmedal

Copy link
Copy Markdown
Collaborator

Code review

No blocking issues. The change is correct — strip_trailing_semicolon is already imported at mysql.py:21-24, and it matches the pattern already on main for bigquery, duckdb and redshift (#2482). Two notes.

1. This is a consistency change, not a fix. cursor.execute("SELECT 1;") succeeds against MySQL today, so nothing user-visible is repaired. The fix(...) prefix and the "Motivation" section read as though a broken path is being closed. Worth relabelling so the changelog doesn't imply that.

2. Dead assertion in the new test.

sent = cursor.execute.call_args[0][0]
assert "LIMIT 2" in sent
assert ";)" not in sent
assert not sent.rstrip().endswith(";")

assert ";)" not in sent is copy-paste residue from the subquery-wrapping connectors. MySQL's _apply_limit appends \nLIMIT n and never wraps the SQL in parentheses, so ";)" cannot occur regardless of the code under test. The line below it already covers the intent.

@Bartok9 Bartok9 changed the title fix(mysql): strip trailing semicolon on unlimited query path refactor(mysql): strip trailing semicolon on unlimited query path for connector consistency Jul 28, 2026
@Bartok9

Bartok9 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @goldmedal — both spot-on.

  1. Retitled to refactor(...) since MySQL's cursor.execute("SELECT 1;") succeeds today; this aligns the connector with bigquery/duckdb/redshift (fix(redshift): strip trailing semicolon on unlimited query path #2482) rather than repairing a broken path.
  2. Dropped the dead assert ";)" not in sent — copy-paste residue from the subquery-wrapping connectors; MySQL's _apply_limit only appends \nLIMIT n and never parenthesizes, so it could never trigger. The trailing-semicolon assertion below already covers the intent.

@goldmedal goldmedal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Bartok9 👍

@goldmedal
goldmedal merged commit 5d2637c into Canner:main Jul 28, 2026
12 checks passed
Bartok9 added a commit to Bartok9/WrenAI that referenced this pull request Jul 31, 2026
Align unlimited `_raw_cursor_sql` with dry_run/limit composition and
sibling connectors (Canner#2595). Not claimed as a pyodbc lone-terminator
failure — consistency only.

Signed-off-by: Bartok9 <danielrpike9@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants