Skip to content

Commit

Permalink
fix(oracle, clickhouse): ensure port is captured in _from_url imp…
Browse files Browse the repository at this point in the history
…lementation (#9507)

## Description of changes
Fix oracle and clickhouse missing `port` in `_from_url`.
  • Loading branch information
grieve54706 authored Jul 9, 2024
1 parent 955a4d7 commit bd3009a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def _from_url(self, url: ParseResult, **kwargs) -> BaseBackend:
"password": unquote_plus(url.password or ""),
"host": url.hostname,
"database": database or "",
"port": url.port,
**kwargs,
}

Expand Down
20 changes: 20 additions & 0 deletions ibis/backends/clickhouse/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
import ibis.expr.datatypes as dt
import ibis.expr.types as ir
from ibis import config, udf
from ibis.backends.clickhouse.tests.conftest import (
CLICKHOUSE_HOST,
CLICKHOUSE_PASS,
CLICKHOUSE_PORT,
CLICKHOUSE_USER,
IBIS_TEST_CLICKHOUSE_DB,
)
from ibis.util import gen_name

cc = pytest.importorskip("clickhouse_connect")
Expand Down Expand Up @@ -359,3 +366,16 @@ def test_password_with_bracket():
cc.driver.exceptions.DatabaseError, match="password is incorrect"
):
ibis.clickhouse.connect(host=host, user=user, port=port, password=quoted_pass)


def test_from_url(con):
assert ibis.connect(
f"clickhouse://{CLICKHOUSE_USER}:{CLICKHOUSE_PASS}@{CLICKHOUSE_HOST}:{CLICKHOUSE_PORT}/{IBIS_TEST_CLICKHOUSE_DB}"
)


def test_invalid_port(con):
port = 9999
url = f"clickhouse://{CLICKHOUSE_USER}:{CLICKHOUSE_PASS}@{CLICKHOUSE_HOST}:{port}/{IBIS_TEST_CLICKHOUSE_DB}"
with pytest.raises(cc.driver.exceptions.DatabaseError):
ibis.connect(url)
1 change: 1 addition & 0 deletions ibis/backends/oracle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def _from_url(self, url: ParseResult, **kwargs):
user=url.username,
password=unquote_plus(url.password) if url.password is not None else None,
database=url.path.removeprefix("/"),
port=url.port,
**kwargs,
)

Expand Down
16 changes: 16 additions & 0 deletions ibis/backends/oracle/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

from datetime import date # noqa: TCH003

import oracledb
import pandas as pd
import pandas.testing as tm
import pytest

import ibis
import ibis.common.exceptions as exc
from ibis import udf
from ibis.backends.oracle.tests.conftest import (
ORACLE_HOST,
ORACLE_PASS,
ORACLE_USER,
)


def test_ibis_is_not_defeated_by_statement_cache(con):
Expand Down Expand Up @@ -77,3 +83,13 @@ def test_from_url(con):
new_con = ibis.connect("oracle://ibis:ibis@localhost:1521/IBIS_TESTING")

assert new_con.list_tables()


def test_invalid_port(con):
port = 9999
url = f"oracle://{ORACLE_USER}:{ORACLE_PASS}@{ORACLE_HOST}:{port}/IBIS_TESTING"
with pytest.raises(
oracledb.OperationalError,
match="DPY-6005: cannot connect to database",
):
ibis.connect(url)

0 comments on commit bd3009a

Please sign in to comment.