Skip to content

Commit

Permalink
added more validations to load utils
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Jun 27, 2024
1 parent 1a1fce2 commit cff6add
Showing 1 changed file with 20 additions and 3 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

0 comments on commit cff6add

Please sign in to comment.