Skip to content

Commit 05d047d

Browse files
committed
fix(ibis): add credentials type validation to TableDataset. Appease mypy and surface explicit errors for invalid credential inputs.
1 parent 90db8d2 commit 05d047d

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

kedro-datasets/kedro_datasets/ibis/table_dataset.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ def __init__( # noqa: PLR0913
148148

149149
self._table_name = table_name
150150
self._database = database
151-
self._connection_config = connection or (
152-
self.DEFAULT_CONNECTION_CONFIG if not credentials else credentials
153-
)
151+
self._connection_config = connection or self.DEFAULT_CONNECTION_CONFIG
154152
# Credentials overlay connection config
155-
self._connection_config.update(credentials or {})
153+
if credentials:
154+
if isinstance(credentials, dict):
155+
self._connection_config.update(credentials)
156+
elif isinstance(credentials, str):
157+
raise ValueError("Connection string credentials are not supported for Ibis TableDataset.")
158+
else:
159+
raise TypeError("Credentials must be a dict or None.")
156160
self.metadata = metadata
157161

158162
# Set load and save arguments, overwriting defaults if provided.

kedro-datasets/tests/ibis/test_table_dataset.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,32 @@ def test_connection_config_with_credentials(
416416
table_dataset.load()
417417
assert ("ibis", key) in table_dataset._connections
418418

419+
@pytest.mark.parametrize(
420+
"credentials,expected_exception,expected_message",
421+
[
422+
(
423+
"postgresql://user:pass@localhost/db",
424+
ValueError,
425+
"Connection string credentials are not supported",
426+
),
427+
(123, TypeError, "Credentials must be a dict"),
428+
(["backend", "duckdb"], TypeError, "Credentials must be a dict"),
429+
(("backend", "duckdb"), TypeError, "Credentials must be a dict"),
430+
(True, TypeError, "Credentials must be a dict"),
431+
],
432+
)
433+
def test_invalid_credentials_types_raise(
434+
self, database_name, connection_config, credentials, expected_exception, expected_message
435+
):
436+
"""Test that invalid credentials types raise appropriate exceptions."""
437+
with pytest.raises(expected_exception, match=expected_message):
438+
TableDataset(
439+
table_name="test",
440+
database=database_name,
441+
connection=connection_config,
442+
credentials=credentials,
443+
)
444+
419445
def test_save_data_loaded_using_file_dataset(self, file_dataset, table_dataset):
420446
"""Test interoperability of Ibis datasets sharing a database."""
421447
dummy_table = file_dataset.load()

0 commit comments

Comments
 (0)