Repository navigation
fix(oracle): strip trailing semicolon on unlimited query path - #2534
Conversation
Unlimited query left client-pasted trailing `;` intact; strip unconditionally so limited and unlimited paths match other connectors.
WalkthroughOracle 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. ChangesOracle SQL sanitization
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/wren/tests/unit/test_oracle_strip_unlimited_query.py (1)
5-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace 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
OracleConnectorand verify thecursor.executecall usingunittest.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
📒 Files selected for processing (2)
core/wren/src/wren/connector/oracle.pycore/wren/tests/unit/test_oracle_strip_unlimited_query.py
Summary
query()only stripped trailing;when wrapping withROWNUMlimits.License
Touches
core/wren/**(Apache-2.0).Verification
Summary by CodeRabbit
Bug Fixes
Tests