From 03c5512dd121265ca9b1ff65c4208c862414228f Mon Sep 17 00:00:00 2001 From: Merel Theisen <49397448+merelcht@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:19:26 +0100 Subject: [PATCH] Add forward compatibility with renames `_dataset` arguments. (#1587) Signed-off-by: Merel Theisen --- .../kedro_viz/data_access/repositories/catalog.py | 13 ++++++++++--- package/kedro_viz/integrations/kedro/hooks.py | 7 +++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/package/kedro_viz/data_access/repositories/catalog.py b/package/kedro_viz/data_access/repositories/catalog.py index 9bfc4d78f3..cb1b698753 100644 --- a/package/kedro_viz/data_access/repositories/catalog.py +++ b/package/kedro_viz/data_access/repositories/catalog.py @@ -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. @@ -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(): @@ -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: diff --git a/package/kedro_viz/integrations/kedro/hooks.py b/package/kedro_viz/integrations/kedro/hooks.py index d51291c03b..b46d58e053 100644 --- a/package/kedro_viz/integrations/kedro/hooks.py +++ b/package/kedro_viz/integrations/kedro/hooks.py @@ -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):