fix(trino): URL-decode credentials and identifiers from connection URL#2435
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe Trino connector now percent-decodes URL credentials and path identifiers while preserving literal ChangesTrino connector parsing and validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
_parse_trino_url passed parsed.username/password and catalog/schema path parts to connect kwargs raw. urlparse leaves percent-encoded characters in userinfo and path, so a credential or identifier containing a reserved character (@ / : ?) — which MUST be percent-encoded in the URL — reached Trino as the literal %40 etc. Decode with unquote (not unquote_plus so a literal + is preserved), matching the mssql/mysql/oracle connectors. Closes nothing — pure silent auth/catalog failure without issue number.
704e2cf to
2157cfd
Compare
|
The fix looks correct, but heads-up: the new regression tests don't run in CI.
This is a pre-existing gap (the whole Cheapest durable fix: split the pure |
The container-backed test_trino.py is not exercised by any CI job (test-unit runs tests/unit/, test-connector only covers postgres+mysql), so the URL-decode regression tests never ran. Split the pure _parse_trino_url / _parse_trino_data_type / _build_trino_column / _strip_trailing_semicolon / lazy-import tests into tests/unit/test_trino_parser.py (no testcontainers import) so the test-unit job collects and runs them. The container suite stays in tests/connectors/test_trino.py.
|
Good catch, thanks — done. I split the pure |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/wren/tests/unit/test_trino_parser.py (1)
235-245: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
monkeypatchforsys.modulesmutations to ensure cleanup.
test_native_connector_does_not_import_ibispops"ibis"and"wren.connector.trino"fromsys.modulesdirectly withoutmonkeypatch, so these mutations persist after the test completes. If a later test in the same session depends on either module being cached, it could fail or experience altered behavior. Usingmonkeypatch.delitem(ormonkeypatch.setitemwith the original value) ensures automatic restoration.♻️ Proposed refactor using monkeypatch
-def test_native_connector_does_not_import_ibis() -> None: +def test_native_connector_does_not_import_ibis(monkeypatch) -> None: # Acceptance criterion: importing the native trino connector must not # pull ibis into sys.modules (the new module is independent of # ibis-framework[trino]). import sys # noqa: PLC0415 - sys.modules.pop("ibis", None) - sys.modules.pop("wren.connector.trino", None) + monkeypatch.delitem(sys.modules, "ibis", raising=False) + monkeypatch.delitem(sys.modules, "wren.connector.trino", raising=False) import wren.connector.trino # noqa: F401, PLC0415 assert "ibis" not in sys.modules🤖 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_trino_parser.py` around lines 235 - 245, Update test_native_connector_does_not_import_ibis to accept pytest’s monkeypatch fixture and replace direct sys.modules.pop calls with monkeypatch.delitem(..., raising=False), ensuring module entries are automatically restored after the test.
🤖 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_trino_parser.py`:
- Around line 235-245: Update test_native_connector_does_not_import_ibis to
accept pytest’s monkeypatch fixture and replace direct sys.modules.pop calls
with monkeypatch.delitem(..., raising=False), ensuring module entries are
automatically restored after the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 40f350d5-758d-4e04-9163-3b4a655509a1
📒 Files selected for processing (2)
core/wren/tests/connectors/test_trino.pycore/wren/tests/unit/test_trino_parser.py
Summary
_parse_trino_urlnowunquote()s the username, password, catalog, and schema parsed out of the connection URL.Motivation
_parse_trino_url(incore/wren/src/wren/connector/trino.py) parsed atrino://user:pass@host:port/catalog/schemaURL and putparsed.username/parsed.password/ the catalog+schema path parts straight into the connect kwargs.urllib.parse.urlparseleaves percent-encoded characters in the userinfo and path. Credentials and identifiers can contain reserved characters (@,/,:,?) that must be percent-encoded for the URL to parse — so a password likep@ss/word(...:p%40ss%2Fword@...) reached Trino as the literalp%40ss%2Fword, and a catalog namedcat/alog(cat%2Falog) was mis-parsed.The mssql, mysql, clickhouse, and oracle connectors already
unquote()these components. This brings Trino in line.unquote(notunquote_plus) is used so a literal+in a credential is preserved.Verification
Real output on current
upstream/main(fix reverted, tests present):With the fix applied:
+is preserved.core/**).Summary by CodeRabbit
+characters in Trino userinfo.ibis.