Skip to content

Commit

Permalink
fix(backends): pass kwargs to _from_url() in every case (ibis-project…
Browse files Browse the repository at this point in the history
…#10003)

Co-authored-by: Phillip Cloud <[email protected]>
  • Loading branch information
nextchamp-saqib and cpcloud authored Sep 5, 2024
1 parent ba07da7 commit 9ca92f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ibis/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,11 +1396,12 @@ def connect(resource: Path | str, **kwargs: Any) -> BaseBackend:
if len(value) == 1:
kwargs[name] = value[0]

# Merge explicit kwargs with query string, explicit kwargs
# taking precedence
kwargs.update(orig_kwargs)

if scheme == "file":
path = parsed.netloc + parsed.path
# Merge explicit kwargs with query string, explicit kwargs
# taking precedence
kwargs.update(orig_kwargs)
if path.endswith(".duckdb"):
return ibis.duckdb.connect(path, **kwargs)
elif path.endswith((".sqlite", ".db")):
Expand Down
13 changes: 12 additions & 1 deletion ibis/backends/clickhouse/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,18 @@ def test_from_url(con):
)


def test_invalid_port(con):
def test_from_url_with_kwargs(con):
# since explicit kwargs take precedence, this passes, because we're passing
# `database` explicitly, even though our connection string says to use a
# random database
database = ibis.util.gen_name("clickhouse_database")
assert ibis.connect(
f"clickhouse://{CLICKHOUSE_USER}:{CLICKHOUSE_PASS}@{CLICKHOUSE_HOST}:{CLICKHOUSE_PORT}/{database}",
database=IBIS_TEST_CLICKHOUSE_DB,
)


def test_invalid_port():
port = 9999
url = f"clickhouse://{CLICKHOUSE_USER}:{CLICKHOUSE_PASS}@{CLICKHOUSE_HOST}:{port}/{IBIS_TEST_CLICKHOUSE_DB}"
with pytest.raises(cc.driver.exceptions.DatabaseError):
Expand Down

0 comments on commit 9ca92f0

Please sign in to comment.