Skip to content

Commit

Permalink
Add forward compatibility with renames _dataset arguments. (#1587)
Browse files Browse the repository at this point in the history
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
  • Loading branch information
merelcht authored Oct 18, 2023
1 parent a22b635 commit 03c5512
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 10 additions & 3 deletions package/kedro_viz/data_access/repositories/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def _validate_layers_for_transcoding(self, dataset_name, layer):

@property
def layers_mapping(self):
# pylint: disable=too-many-branches
"""Return layer mapping: dataset_name -> layer it belongs to in the catalog
From kedro-datasets 1.3.0 onwards, the 'layers' attribute is defined inside the 'metadata'
under 'kedro-viz' plugin.
Expand All @@ -78,12 +79,18 @@ def layers_mapping(self):

self._layers_mapping = {}

# Temporary try/except block so the Kedro develop branch can work with Viz.
try:
datasets = self._catalog._data_sets
# pylint: disable=broad-exception-caught
except Exception: # pragma: no cover
datasets = self._catalog._datasets

# Maps layers according to the old format
if KEDRO_VERSION < parse("0.19.0"):
if self._catalog.layers is None:
self._layers_mapping = {
_strip_transcoding(dataset_name): None
for dataset_name in self._catalog._data_sets
_strip_transcoding(dataset_name): None for dataset_name in datasets
}
else:
for layer, dataset_names in self._catalog.layers.items():
Expand All @@ -94,7 +101,7 @@ def layers_mapping(self):
self._layers_mapping[dataset_name] = layer

# Maps layers according to the new format
for dataset_name in self._catalog._data_sets:
for dataset_name in datasets:
dataset = self._catalog._get_dataset(dataset_name)
metadata = getattr(dataset, "metadata", None)
if not metadata:
Expand Down
7 changes: 5 additions & 2 deletions package/kedro_viz/integrations/kedro/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ def after_catalog_created(self, catalog: DataCatalog):
Args:
catalog: The catalog that was created.
"""

self.datasets = catalog._data_sets
# Temporary try/except block so the Kedro develop branch can work with Viz.
try:
self.datasets = catalog._data_sets
except Exception: # pragma: no cover
self.datasets = catalog._datasets # type: ignore[attr-defined]

@hook_impl
def after_dataset_loaded(self, dataset_name: str, data: Any):
Expand Down

0 comments on commit 03c5512

Please sign in to comment.