diff --git a/client/ayon_core/pipeline/load/utils.py b/client/ayon_core/pipeline/load/utils.py index f3d39800cd..256ab5853b 100644 --- a/client/ayon_core/pipeline/load/utils.py +++ b/client/ayon_core/pipeline/load/utils.py @@ -1,9 +1,11 @@ import os +import uuid import platform import logging import inspect import collections import numbers +from typing import Any import ayon_api @@ -464,8 +466,13 @@ def update_container(container, version=-1): # Compute the different version from 'representation' project_name = get_current_project_name() + repre_id = container["representation"] + if not _is_valid_representation_id(repre_id): + raise ValueError( + f"Got container with invalid representation id '{repre_id}'" + ) current_representation = ayon_api.get_representation_by_id( - project_name, container["representation"] + project_name, repre_id ) assert current_representation is not None, "This is a bug" @@ -817,6 +824,16 @@ def get_outdated_containers(host=None, project_name=None): return filter_containers(containers, project_name).outdated +def _is_valid_representation_id(repre_id: Any) -> bool: + if not repre_id: + return False + try: + uuid.UUID(repre_id) + except (ValueError, TypeError, AttributeError): + return False + return True + + def filter_containers(containers, project_name): """Filter containers and split them into 4 categories. @@ -852,7 +869,7 @@ def filter_containers(containers, project_name): repre_ids = { container["representation"] for container in containers - if container["representation"] + if _is_valid_representation_id(container["representation"]) } if not repre_ids: if containers: @@ -917,7 +934,7 @@ def filter_containers(containers, project_name): for container in containers: container_name = container["objectName"] repre_id = container["representation"] - if not repre_id: + if not _is_valid_representation_id(repre_id): invalid_containers.append(container) continue diff --git a/client/ayon_core/tools/sceneinventory/model.py b/client/ayon_core/tools/sceneinventory/model.py index 335df87b95..a40d110476 100644 --- a/client/ayon_core/tools/sceneinventory/model.py +++ b/client/ayon_core/tools/sceneinventory/model.py @@ -147,6 +147,7 @@ def refresh(self, selected=None): product_ids = { repre_info.product_id for repre_info in repre_info_by_id.values() + if repre_info.is_valid } version_items_by_product_id = self._controller.get_version_items( product_ids @@ -227,12 +228,13 @@ def refresh(self, selected=None): status_name ) + repre_name = ( + repre_info.representation_name or "" + ) container_model_items = [] for container_item in container_items: - unique_name = ( - repre_info.representation_name - + container_item.object_name or "" - ) + object_name = container_item.object_name or "" + unique_name = repre_name + object_name item = QtGui.QStandardItem() item.setColumnCount(root_item.columnCount()) diff --git a/client/ayon_core/tools/sceneinventory/models/containers.py b/client/ayon_core/tools/sceneinventory/models/containers.py index c3881ea40d..871455c96b 100644 --- a/client/ayon_core/tools/sceneinventory/models/containers.py +++ b/client/ayon_core/tools/sceneinventory/models/containers.py @@ -358,9 +358,20 @@ def _update_cache(self): container_items = [] containers_by_id = {} container_items_by_id = {} + invalid_ids_mapping = {} for container in containers: try: item = ContainerItem.from_container_data(container) + repre_id = item.representation_id + try: + uuid.UUID(repre_id) + except (ValueError, TypeError, AttributeError): + # Fake not existing representation id so container is shown in UI + # but as invalid + item.representation_id = invalid_ids_mapping.setdefault( + repre_id, uuid.uuid4().hex + ) + except Exception as e: # skip item if required data are missing self._controller.log_error(