Skip to content

Commit

Permalink
Fix credentials throwing error on kedro catalog resolve (#3712)
Browse files Browse the repository at this point in the history
* Feed credentials to catalog in catalog resolve command

Signed-off-by: Merel Theisen <[email protected]>
  • Loading branch information
merelcht authored Mar 18, 2024
1 parent 0b6e1a9 commit 0fe2f17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

## Bug fixes and other changes
* Updated `kedro pipeline create` and `kedro pipeline delete` to read the base environment from the project settings.
* Updated CLI command `kedro catalog resolve` to read credentials properly.

## Breaking changes to the API
* Methods `_is_project` and `_find_kedro_project` have been moved to `kedro.utils`. We recommend not using private methods in your code, but if you do, please update your code to use the new location.
Expand Down
5 changes: 4 additions & 1 deletion kedro/framework/cli/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ def resolve_patterns(metadata: ProjectMetadata, env: str) -> None:
context = session.load_context()

catalog_config = context.config_loader["catalog"]
data_catalog = DataCatalog.from_config(catalog_config)
credentials_config = context.config_loader.get("credentials", None)
data_catalog = DataCatalog.from_config(
catalog=catalog_config, credentials=credentials_config
)

explicit_datasets = {
ds_name: ds_config
Expand Down
22 changes: 19 additions & 3 deletions tests/framework/cli/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ def mock_pipelines(mocker):
return mocker.patch("kedro.framework.cli.catalog.pipelines", dummy_pipelines)


@pytest.fixture()
def fake_credentials_config(tmp_path):
return {"db_connection": {"con": "foo"}}


@pytest.fixture
def fake_catalog_config():
config = {
"parquet_{factory_pattern}": {
"type": "pandas.ParquetDataset",
"filepath": "data/01_raw/{factory_pattern}.pq",
"credentials": "db_connection",
},
"csv_{factory_pattern}": {
"type": "pandas.CSVDataset",
Expand All @@ -50,6 +56,7 @@ def fake_catalog_config_resolved():
"parquet_example": {
"type": "pandas.ParquetDataset",
"filepath": "data/01_raw/example.pq",
"credentials": {"con": "foo"},
},
"csv_example": {
"type": "pandas.CSVDataset",
Expand Down Expand Up @@ -271,13 +278,16 @@ def test_list_factory_generated_datasets(
mocker,
mock_pipelines,
fake_catalog_config,
fake_credentials_config,
):
"""Test that datasets generated from factory patterns in the catalog
are resolved correctly under the correct dataset classes.
"""
yaml_dump_mock = mocker.patch("yaml.dump", return_value="Result YAML")
mocked_context = fake_load_context.return_value
mocked_context.catalog = DataCatalog.from_config(fake_catalog_config)
mocked_context.catalog = DataCatalog.from_config(
catalog=fake_catalog_config, credentials=fake_credentials_config
)
mocker.patch.object(
mock_pipelines[PIPELINE_NAME],
"datasets",
Expand Down Expand Up @@ -526,11 +536,17 @@ def test_catalog_resolve(
mock_pipelines,
fake_catalog_config,
fake_catalog_config_resolved,
fake_credentials_config,
):
"""Test that datasets factories are correctly resolved to the explicit datasets in the pipeline."""
mocked_context = fake_load_context.return_value
mocked_context.config_loader = {"catalog": fake_catalog_config}
mocked_context.catalog = DataCatalog.from_config(fake_catalog_config)
mocked_context.config_loader = {
"catalog": fake_catalog_config,
"credentials": fake_credentials_config,
}
mocked_context.catalog = DataCatalog.from_config(
catalog=fake_catalog_config, credentials=fake_credentials_config
)
placeholder_ds = mocked_context.catalog._dataset_patterns.keys()
pipeline_datasets = {"csv_example", "parquet_example", "explicit_dataset"}

Expand Down

0 comments on commit 0fe2f17

Please sign in to comment.