added more validations to load utils

This commit is contained in:
Jakub Trllo 2024-06-27 18:18:10 +02:00
parent 1a1fce289d
commit cff6add784

View file

@ -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