Skip to content

fix(sdk): URL-decode ClickHouse connection-URL credentials and database - #2444

Merged
goldmedal merged 1 commit into
Canner:mainfrom
Bartok9:fix/clickhouse-url-decode
Jul 10, 2026
Merged

fix(sdk): URL-decode ClickHouse connection-URL credentials and database#2444
goldmedal merged 1 commit into
Canner:mainfrom
Bartok9:fix/clickhouse-url-decode

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • DataSource.clickhouse now URL-decodes the username, password, and database parsed from a connectionUrl.
  • The password is decoded with unquote instead of unquote_plus, so a literal + in a password is preserved instead of being turned into a space.

Motivation

_handle_clickhouse_url in core/wren/src/wren/model/data_source.py:

  • decoded the password with unquote_plus, which maps + → space. A ClickHouse password containing a + therefore silently connected with the wrong credential.
  • did not decode the username or database at all, so percent-escapes (e.g. %40 for @, %20 for a space) survived as literal text and produced auth/lookup failures.

This brings the SDK path in line with the connector-level handling already used for mssql and mysql, which use unquote.

Verification

$ python -m pytest tests/unit/test_clickhouse_url.py -q
3 passed

# on current main (git stash of the fix):
FAILED test_plus_in_password_is_preserved     (pa ss != pa+ss)
FAILED test_username_and_database_are_decoded  (us%40er != us@er)
2 failed, 1 passed

The new regression tests fail on main and pass with the fix. ruff format and ruff check clean. Change is confined to Apache-2.0 core/wren/**.

Summary by CodeRabbit

  • Bug Fixes

    • Improved ClickHouse connection URL handling so percent-encoded usernames, passwords, and database names are decoded correctly.
    • Preserved literal + characters in credentials instead of converting them to spaces.
  • Tests

    • Added coverage for ClickHouse connection parsing to verify decoding behavior and prevent regressions.

_handle_clickhouse_url decoded the password with unquote_plus (turning a
literal '+' into a space) and left the username and database name
percent-encoded. Use unquote for all three so a connectionUrl like
clickhouse://us%40er:pa+ss@host/my%20db yields user 'us@er', password 'pa+ss',
and database 'my db'. Matches the connector-level handling already used for
mssql/mysql.
@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 286a50a3-c729-410e-9968-4b96e1fe8d66

📥 Commits

Reviewing files that changed from the base of the PR and between 797f439 and b51671f.

📒 Files selected for processing (2)
  • core/wren/src/wren/model/data_source.py
  • core/wren/tests/unit/test_clickhouse_url.py

Walkthrough

This PR fixes ClickHouse connection URL parsing to use urllib.parse.unquote instead of unquote_plus for decoding username, password, and database fields, preserving literal + characters while decoding percent-encoded values. Unit tests validate the corrected behavior.

Changes

ClickHouse Credential Decoding Fix

Layer / File(s) Summary
Switch to unquote for URL decoding
core/wren/src/wren/model/data_source.py
Replaces unquote_plus import with unquote and applies it to username, password, and database segments in _handle_clickhouse_url, with comments explaining the preservation of literal + characters.
Regression tests for URL decoding
core/wren/tests/unit/test_clickhouse_url.py
Adds a new test module with a helper function and three tests confirming plus-sign preservation and correct decoding of percent-encoded username, database, and password values.

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

Sequence Diagram(s)

Not applicable; this change is a targeted bug fix without multi-component control flow.

Poem

A plus sign hopped, refused to bend,
No more spaces, my old foe-friend! 🐰
With unquote's magic, credentials shine true,
Percent-signs decoded, username too.
Hop hop hooray, the tests all pass,
This bunny's proud of this fixed-up class! 🥕

🚥 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 and concisely describes the main change: URL-decoding ClickHouse connection URL credentials and database.
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.

@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 f178cfe into Canner:main Jul 10, 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