diff --git a/ibis/backends/clickhouse/__init__.py b/ibis/backends/clickhouse/__init__.py index e5b773afea0a..84d59b4fa7d6 100644 --- a/ibis/backends/clickhouse/__init__.py +++ b/ibis/backends/clickhouse/__init__.py @@ -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, } diff --git a/ibis/backends/clickhouse/tests/test_client.py b/ibis/backends/clickhouse/tests/test_client.py index d9ccf75d1625..487862bb2e4e 100644 --- a/ibis/backends/clickhouse/tests/test_client.py +++ b/ibis/backends/clickhouse/tests/test_client.py @@ -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") @@ -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) diff --git a/ibis/backends/oracle/__init__.py b/ibis/backends/oracle/__init__.py index d2cf6ddda922..bce452dc44cb 100644 --- a/ibis/backends/oracle/__init__.py +++ b/ibis/backends/oracle/__init__.py @@ -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, ) diff --git a/ibis/backends/oracle/tests/test_client.py b/ibis/backends/oracle/tests/test_client.py index 6ddcb3263689..e5227cbc0303 100644 --- a/ibis/backends/oracle/tests/test_client.py +++ b/ibis/backends/oracle/tests/test_client.py @@ -2,6 +2,7 @@ from datetime import date # noqa: TCH003 +import oracledb import pandas as pd import pandas.testing as tm import pytest @@ -9,6 +10,11 @@ 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): @@ -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)