diff --git a/client/ayon_core/plugins/publish/collect_explicit_resolution.py b/client/ayon_core/plugins/publish/collect_explicit_resolution.py index 1aa7147627..1a388d5487 100644 --- a/client/ayon_core/plugins/publish/collect_explicit_resolution.py +++ b/client/ayon_core/plugins/publish/collect_explicit_resolution.py @@ -50,21 +50,21 @@ class CollectExplicitResolution( dict: dictionary with width, height and pixel_aspect """ resolution_items = self._get_resolution_items() - item_values = None - # check if resolution_value is in cached items - if resolution_value in resolution_items: - item_values = resolution_items[resolution_value] + # ensure resolution_value is part of expected items + item_values = resolution_items.get(resolution_value) + # if the item is in the cache, get the values from it if item_values: - # if the item is in the cache, get the values from it return { "resolutionWidth": item_values["width"], "resolutionHeight": item_values["height"], "pixelAspect": item_values["pixel_aspect"], } - else: - raise PublishError( - f"Invalid resolution value: {resolution_value}") + + raise PublishError( + f"Invalid resolution value: {resolution_value} " + f"expected choices: {resolution_items}" + ) @classmethod def _get_resolution_items(cls): @@ -72,7 +72,7 @@ class CollectExplicitResolution( resolution_items = {} for item in cls.options: item_text = ( - f"{item['width']}x{item['height']}x{item['pixel_aspect']}") + f"{item['width']}x{item['height']} ({item['pixel_aspect']})") resolution_items[item_text] = item cls.resolution_items = resolution_items diff --git a/server/settings/publish_plugins.py b/server/settings/publish_plugins.py index 7ad6c9c506..cce312c2f8 100644 --- a/server/settings/publish_plugins.py +++ b/server/settings/publish_plugins.py @@ -191,21 +191,21 @@ class ResolutionOptionsModel(BaseSettingsModel): def ensure_unique_resolution_option( - objects: Iterable[Any], field_name: str | None = None) -> None: # noqa: C901 + objects: list[Any], field_name: str | None = None) -> None: # noqa: C901 """Ensure a list of objects have unique option attributes. This function checks if the list of objects has unique 'width', 'height' and 'pixel_aspect' properties. """ - options = [] + options = set() for obj in objects: item_test_text = f"{obj.width}x{obj.height}x{obj.pixel_aspect}" - if item_test_text not in options: - options.append(item_test_text) - else: + if item_test_text in options: raise BadRequestException( f"Duplicate option '{item_test_text}'") + options.add(item_test_text) + class CollectExplicitResolutionModel(BaseSettingsModel): enabled: bool = SettingsField(True, title="Enabled") @@ -218,14 +218,14 @@ class CollectExplicitResolutionModel(BaseSettingsModel): ) options: list[ResolutionOptionsModel] = SettingsField( default_factory=list, - title="Resolution options", + title="Resolution choices", description=( - "Options to be provided in publisher attribute" + "Available resolution choices to be displayed in the publishers attribute." ) ) @validator("options") - def validate_unique_options(cls, value): + def validate_unique_resolution_options(cls, value): ensure_unique_resolution_option(value) return value