Skip to content

fix(oracle): strip trailing semicolon on unlimited query path - #2534

Merged
goldmedal merged 1 commit into
Canner:mainfrom
Bartok9:fix/oracle-strip-unlimited-semicolon
Jul 23, 2026
Merged

goldmedal merged 1 commit into
Canner:mainfrom
Bartok9:fix/oracle-strip-unlimited-semicolon

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Oracle query() only stripped trailing ; when wrapping with ROWNUM limits.
  • Unlimited executes forwarded client-pasted terminators and could fail.
  • Strip unconditionally; wrap the already-stripped SQL when limit is set.

License

Touches core/wren/** (Apache-2.0).

Verification

python3 -m pytest core/wren/tests/unit/test_oracle_strip_unlimited_query.py -q
# 2 passed

Summary by CodeRabbit

  • Bug Fixes

    • Oracle queries now consistently remove trailing semicolons before execution, including queries without a row limit.
    • Improved compatibility for unlimited Oracle query execution.
  • Tests

    • Added coverage verifying semicolon removal for unlimited queries.
    • Added regression coverage for the previous execution path.

Unlimited query left client-pasted trailing `;` intact; strip
unconditionally so limited and unlimited paths match other connectors.
@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Oracle query preprocessing now removes trailing semicolons before both limited and unlimited execution paths. New unit tests verify the unconditional sanitization and document the previous unlimited-query behavior.

Changes

Oracle SQL sanitization

Layer / File(s) Summary
Sanitize Oracle queries before execution
core/wren/src/wren/connector/oracle.py, core/wren/tests/unit/test_oracle_strip_unlimited_query.py
OracleConnector.query strips trailing semicolons before limit handling. Tests verify the source-level call, quoted-semicolon regex behavior, and the former unlimited-path result.

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

Possibly related PRs

  • Canner/WrenAI#2480: Standardizes trailing-semicolon stripping through the shared Oracle connector helper.
  • Canner/WrenAI#2423: Fixes semicolon removal before connector subquery wrapping.
  • Canner/WrenAI#2477: Applies unconditional trailing-semicolon stripping in another connector query path.

Suggested reviewers: goldmedal

Poem

I’m a rabbit with SQL in my paws,
Trimming semicolons without pause.
Limited or free, the query runs clean,
Quotes keep their semicolons keen.
Hop, hop—tests guard the scene!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: Oracle unlimited queries now strip trailing semicolons.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
core/wren/tests/unit/test_oracle_strip_unlimited_query.py (1)

5-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace source-code inspection and dummy tests with standard unit tests.

Reading the source file text to assert a specific code string is highly brittle and couples the test to exact formatting. Furthermore, the second test verifies a simulated internal dummy function rather than the actual OracleConnector, providing no real regression protection.

Please consider replacing these with standard behavior tests that instantiate OracleConnector and verify the cursor.execute call using unittest.mock.

♻️ Proposed fix using `unittest.mock`
-import re
-from pathlib import Path
-
-
-def test_query_unlimited_path_strips_trailing_semicolon():
-    src = (
-        Path(__file__).resolve().parents[2]
-        / "src"
-        / "wren"
-        / "connector"
-        / "oracle.py"
-    ).read_text(encoding="utf-8")
-    # Unlimited branch used to pass `sql` through unchanged after the
-    # limited branch. Require an unconditional strip for both paths.
-    assert "sql = strip_trailing_semicolon(sql)" in src
-
-    # Helper behaviour (same regex as production):
-    helper = re.compile(r"[;\s]+\Z")
-    assert helper.sub("", "SELECT 1;") == "SELECT 1"
-    assert helper.sub("", "SELECT 'a;b'") == "SELECT 'a;b'"
-
-
-def test_without_unconditional_strip_semicolon_would_reach_execute():
-    """Document pre-fix behaviour: only the limit branch stripped."""
-    # Simulated old code path for regression documentation.
-    def old_query(sql: str, limit: int | None = None) -> str:
-        if limit is not None:
-            sql = re.sub(r"[;\s]+\Z", "", sql)
-            sql = f"SELECT * FROM ({sql}) t WHERE ROWNUM <= {limit}"
-        return sql
-
-    assert old_query("SELECT 1;", None) == "SELECT 1;"
-    assert old_query("SELECT 1;", 10).startswith("SELECT * FROM (SELECT 1)")
+import sys
+from unittest.mock import MagicMock, patch
+
+# Mock oracledb if it is an optional dependency not present in the test environment
+sys.modules["oracledb"] = MagicMock()
+from wren.connector.oracle import OracleConnector
+
+
+@patch("wren.connector.oracle._build_oracle_arrow_table")
+@patch("wren.connector.oracle._make_oracle_connection")
+def test_query_strips_trailing_semicolon(mock_make_conn, mock_build_table):
+    mock_cursor = MagicMock()
+    mock_make_conn.return_value.cursor.return_value.__enter__.return_value = mock_cursor
+    
+    connector = OracleConnector({})
+    
+    # Unlimited path
+    connector.query("SELECT 1;", limit=None)
+    mock_cursor.execute.assert_called_with("SELECT 1")
+    
+    # Limited path
+    connector.query("SELECT 2;", limit=10)
+    mock_cursor.execute.assert_called_with("SELECT * FROM (SELECT 2) t WHERE ROWNUM <= 10")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/wren/tests/unit/test_oracle_strip_unlimited_query.py` around lines 5 -
38, Replace the source-text and simulated old_query assertions in the two tests
with behavior-focused unit tests for OracleConnector. Instantiate
OracleConnector with the required mocked dependencies, invoke its query method
for both unlimited and limited paths, and use unittest.mock to verify
cursor.execute receives SQL without trailing semicolons while preserving the
existing limit behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@core/wren/tests/unit/test_oracle_strip_unlimited_query.py`:
- Around line 5-38: Replace the source-text and simulated old_query assertions
in the two tests with behavior-focused unit tests for OracleConnector.
Instantiate OracleConnector with the required mocked dependencies, invoke its
query method for both unlimited and limited paths, and use unittest.mock to
verify cursor.execute receives SQL without trailing semicolons while preserving
the existing limit behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cfada16b-ddb2-49ed-adc0-259243e8380d

📥 Commits

Reviewing files that changed from the base of the PR and between 3dac00a and 9b23fff.

📒 Files selected for processing (2)
  • core/wren/src/wren/connector/oracle.py
  • core/wren/tests/unit/test_oracle_strip_unlimited_query.py

@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 78b5b93 into Canner:main Jul 23, 2026
10 checks passed
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