Skip to content

fix(connector): coerce non-string SQL in strip_trailing_semicolon#2539

Open
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/strip-trailing-nonstring-coercion
Open

fix(connector): coerce non-string SQL in strip_trailing_semicolon#2539
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/strip-trailing-nonstring-coercion

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Coerce non-string sql arguments in strip_trailing_semicolon (None"", other values via str(...)).
  • Prevents TypeError inside the trailing-semicolon regex when callers pass accidental non-strings.

Motivation

Every connector funnels user/limit/EXOLAIN composition through this helper. A None or int SQL argument currently raises TypeError: expected string or bytes-like object deep in re.sub, masking the real caller bug with a generic regex crash.

License

Apache-2.0 path: core/wren/src/wren/connector/base.py (+ unit test).

Verification

cd core/wren && .venv/bin/python -m pytest tests/unit/test_strip_trailing_semicolon_coerce.py -q → 3 passed

Test plan

  • unit tests for string / None / int
  • CI green

Summary by CodeRabbit

  • Bug Fixes

    • Improved SQL statement handling when input is empty, null, or not provided as text.
    • Non-text values are now safely converted to text before trailing semicolons and whitespace are removed.
  • Tests

    • Added coverage for standard strings, null values, and non-text inputs.

@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 19, 2026
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The shared strip_trailing_semicolon helper now handles None and non-string inputs before trimming trailing semicolons. New unit tests cover string, null, and numeric inputs.

Changes

Semicolon Input Normalization

Layer / File(s) Summary
Normalize helper inputs and verify behavior
core/wren/src/wren/connector/base.py, core/wren/tests/unit/test_strip_trailing_semicolon_coerce.py
The helper returns an empty string for None, coerces other non-string values, preserves trailing-semicolon stripping, and adds focused tests for these cases.

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

Possibly related PRs

Suggested reviewers: goldmedal

Poem

I’m a rabbit who trims each tail,
Semicolons vanish without fail.
None hops to an empty line,
Numbers turn to strings just fine.
Tests bloom softly in the trail.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: coercing non-string SQL inputs in strip_trailing_semicolon.
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/src/wren/connector/base.py (1)

19-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update the type hint to match the new behavior.

The function is now intentionally designed to accept None and non-string values. However, the function signature on line 11 still types sql as str (def strip_trailing_semicolon(sql: str) -> str:). This will cause static type checkers to report errors when non-string arguments are passed to this function.

Consider updating the type hint to Any (e.g., sql: Any) to accurately reflect this defensive behavior.

# In core/wren/src/wren/connector/base.py, around line 11:
from typing import Any

def strip_trailing_semicolon(sql: Any) -> str:
🤖 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/src/wren/connector/base.py` around lines 19 - 27, Update the
`strip_trailing_semicolon` parameter annotation to accept the `None` and
non-string values already handled by its implementation, importing `Any` from
`typing` if needed, while keeping the return type as `str`.
🤖 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/src/wren/connector/base.py`:
- Around line 19-27: Update the `strip_trailing_semicolon` parameter annotation
to accept the `None` and non-string values already handled by its
implementation, importing `Any` from `typing` if needed, while keeping the
return type as `str`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0cafb939-d329-405d-9f5f-0343e307f5a4

📥 Commits

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

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

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.

1 participant