Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loader & Scene inventory: Ignore containers with invalid representation id #1037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions client/ayon_core/tools/loader/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,17 @@ def get_loaded_product_ids(self):

repre_ids = set()
for container in containers:
repre_id = container.get("representation")
# Ignore invalid representation ids.
# - invalid representation ids may be available if e.g. is
# opened scene from OpenPype whe 'ObjectId' was used instead
# of 'uuid'.
# NOTE: Server call would crash if there is any invalid id.
# That would cause crash we won't get any information.
try:
repre_id = container.get("representation")
# Ignore invalid representation ids.
# - invalid representation ids may be available if e.g. is
# opened scene from OpenPype whe 'ObjectId' was used
# instead of 'uuid'.
# NOTE: Server call would crash if there is any invalid id.
# That would cause crash we won't get any information.
uuid.UUID(repre_id)
repre_ids.add(repre_id)
except ValueError:
except (ValueError, TypeError, AttributeError):
pass

product_ids = self._products_model.get_product_ids_by_repre_ids(
Expand Down
31 changes: 21 additions & 10 deletions client/ayon_core/tools/sceneinventory/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ayon_api
from ayon_api.graphql import GraphQlQuery

from ayon_core.lib import Logger
from ayon_core.host import ILoadHost
from ayon_core.tools.common_models.projects import StatusStates

Expand Down Expand Up @@ -196,6 +197,7 @@ def __init__(self, controller):
self._container_items_by_id = {}
self._version_items_by_product_id = {}
self._repre_info_by_id = {}
self._log = Logger.get_logger("ContainersModel")

def reset(self):
self._items_cache = None
Expand Down Expand Up @@ -230,7 +232,7 @@ def get_representation_info_items(self, project_name, representation_ids):
for repre_id in representation_ids:
try:
uuid.UUID(repre_id)
except ValueError:
except (ValueError, TypeError, AttributeError):
output[repre_id] = RepresentationInfo.new_invalid()
continue
repre_info = self._repre_info_by_id.get(repre_id)
Expand Down Expand Up @@ -348,36 +350,45 @@ def _update_cache(self):
return

host = self._controller.get_host()
if isinstance(host, ILoadHost):
containers = list(host.get_containers())
elif hasattr(host, "ls"):
containers = list(host.ls())
else:
containers = []
containers = []
try:
if isinstance(host, ILoadHost):
containers = list(host.get_containers())
elif hasattr(host, "ls"):
containers = list(host.ls())
except Exception:
self._log.error("Failed to get containers", exc_info=True)

container_items = []
containers_by_id = {}
container_items_by_id = {}
invalid_ids_mapping = {}
current_project_name = self._controller.get_current_project_name()
for container in containers:
if not container:
continue

try:
item = ContainerItem.from_container_data(
current_project_name, container)
repre_id = item.representation_id
try:
uuid.UUID(repre_id)
except (ValueError, TypeError, AttributeError):
self._log.warning(
"Container contains invalid representation id."
f"\n{container}"
)
# 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:
except Exception:
# skip item if required data are missing
self._controller.log_error(
f"Failed to create item: {e}"
self._log.warning(
"Failed to create container item", exc_info=True
)
continue

Expand Down
Loading