diff --git a/client/ayon_core/pipeline/traits/meta.py b/client/ayon_core/pipeline/traits/meta.py index 9e3e6a43e7..36ad5e8b0f 100644 --- a/client/ayon_core/pipeline/traits/meta.py +++ b/client/ayon_core/pipeline/traits/meta.py @@ -41,4 +41,4 @@ class TemplatePath(TraitBase): description: ClassVar[str] = "Template Path Trait Model" id: ClassVar[str] = "ayon.meta.TemplatePath.v1" template: str = Field(..., title="Template Path") - data: dict[str] = Field(..., title="Formatting Data") + data: dict = Field(..., title="Formatting Data") diff --git a/client/ayon_core/pipeline/traits/trait.py b/client/ayon_core/pipeline/traits/trait.py index 7d8221e370..90be38225b 100644 --- a/client/ayon_core/pipeline/traits/trait.py +++ b/client/ayon_core/pipeline/traits/trait.py @@ -3,6 +3,7 @@ from __future__ import annotations import inspect import sys +import uuid from abc import ABC, abstractmethod from collections import OrderedDict from functools import lru_cache @@ -58,10 +59,16 @@ class Representation: It holds methods to add, remove, get, and check for the existence of a trait in the representation. It also provides a method to get all the + Arguments: + name (str): Representation name. Must be unique within instance. + representation_id (str): Representation ID. + """ _data: dict _module_blacklist: ClassVar[list[str]] = [ "_", "builtins", "pydantic"] + name: str + representation_id: str @lru_cache(maxsize=64) # noqa: B019 def _get_trait_class(self, trait_id: str) -> Union[Type[TraitBase], None]: @@ -343,8 +350,20 @@ class Representation: """Return the length of the data.""" return len(self._data) - def __init__(self, traits: Optional[list[TraitBase]]=None): - """Initialize the data.""" + def __init__( + self, + name: str, + representation_id: Optional[str]=None, + traits: Optional[list[TraitBase]]=None): + """Initialize the data. + + Args: + name (str): Representation name. Must be unique within instance. + representation_id (str, optional): Representation ID. + traits (list[TraitBase], optional): List of traits. + """ + self.name = name + self.representation_id = representation_id or uuid.uuid4().hex self._data = {} if traits: for trait in traits: diff --git a/tests/client/ayon_core/pipeline/traits/test_traits.py b/tests/client/ayon_core/pipeline/traits/test_traits.py index 4c941f3e45..fc38e8fb56 100644 --- a/tests/client/ayon_core/pipeline/traits/test_traits.py +++ b/tests/client/ayon_core/pipeline/traits/test_traits.py @@ -39,7 +39,7 @@ class InvalidTrait: @pytest.fixture() def representation() -> Representation: """Return a traits data instance.""" - return Representation(traits=[ + return Representation(name="test", traits=[ FileLocation(**REPRESENTATION_DATA[FileLocation.id]), Image(), PixelBased(**REPRESENTATION_DATA[PixelBased.id]), @@ -111,7 +111,7 @@ def test_representation_traits(representation: Representation) -> None: repre_dict assert representation.has_traits() is True - empty_representation = Representation(traits=[]) + empty_representation = Representation(name="test", traits=[]) assert empty_representation.has_traits() is False assert representation.contains_trait(trait=FileLocation) is True @@ -205,7 +205,7 @@ def test_bundles() -> None: MimeType(mime_type="image/tiff"), ] bundle = Bundle(items=[diffuse_texture, bump_texture]) - representation = Representation(traits=[bundle]) + representation = Representation(name="test_bundle", traits=[bundle]) if representation.contains_trait(trait=Bundle): assert representation.get_trait(trait=Bundle).items == [ @@ -213,7 +213,7 @@ def test_bundles() -> None: ] for item in representation.get_trait(trait=Bundle).items: - sub_representation = Representation(traits=item) + sub_representation = Representation(name="test", traits=item) assert sub_representation.contains_trait(trait=Image) assert sub_representation.get_trait(trait=MimeType).mime_type in [ "image/jpeg", "image/tiff"