From 06fed885ad5e9a5626baa50dd981856ea98eb183 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 16 Dec 2021 15:47:29 +0100 Subject: [PATCH] breadcrumbs are not brute focing access to child entities by accessing with __getitem__ but checking if 'has_child_with_key' --- .../settings/settings/breadcrumbs_widget.py | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/openpype/tools/settings/settings/breadcrumbs_widget.py b/openpype/tools/settings/settings/breadcrumbs_widget.py index d25cbdc8cb..7524bc61f0 100644 --- a/openpype/tools/settings/settings/breadcrumbs_widget.py +++ b/openpype/tools/settings/settings/breadcrumbs_widget.py @@ -71,17 +71,35 @@ class SettingsBreadcrumbs(BreadcrumbsModel): return True return False + def get_valid_path(self, path): + if not path: + return "" + + path_items = path.split("/") + new_path_items = [] + entity = self.entity + for item in path_items: + if not entity.has_child_with_key(item): + break + + new_path_items.append(item) + entity = entity[item] + + return "/".join(new_path_items) + def is_valid_path(self, path): if not path: return True path_items = path.split("/") - try: - entity = self.entity - for item in path_items: - entity = entity[item] - except Exception: - return False + + entity = self.entity + for item in path_items: + if not entity.has_child_with_key(item): + return False + + entity = entity[item] + return True @@ -436,6 +454,7 @@ class BreadcrumbsAddressBar(QtWidgets.QFrame): self.change_path(path) def change_path(self, path): + path = self._model.get_valid_path(path) if self._model and not self._model.is_valid_path(path): self._show_address_field() else: