Skip to content

Commit

Permalink
Merge pull request #725 from ynput/enhancement/validate-representatio…
Browse files Browse the repository at this point in the history
…n-id

SceneInventory: Ignore containers with invalid UUID in representation
  • Loading branch information
iLLiCiTiT authored Jun 28, 2024
2 parents 5c32f41 + 9ffbd39 commit 293d474
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
23 changes: 20 additions & 3 deletions client/ayon_core/pipeline/load/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions client/ayon_core/tools/sceneinventory/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -227,12 +228,13 @@ def refresh(self, selected=None):
status_name
)

repre_name = (
repre_info.representation_name or "<unknown representation>"
)
container_model_items = []
for container_item in container_items:
unique_name = (
repre_info.representation_name
+ container_item.object_name or "<none>"
)
object_name = container_item.object_name or "<none>"
unique_name = repre_name + object_name

item = QtGui.QStandardItem()
item.setColumnCount(root_item.columnCount())
Expand Down
11 changes: 11 additions & 0 deletions client/ayon_core/tools/sceneinventory/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 293d474

Please sign in to comment.