Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

[QUAD] Bug: Sometime the latest version number cannot be retrieved from instance data, use tracked versions #6343

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions openpype/modules/ftrack/ftrack_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ def initialize(self, settings):
self.timers_manager_connector = None
self._timers_manager_module = None

def get_asset_latest_version_number(self, asset_ftrack_id, task_name, asset_name):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (86 > 79 characters)

try:
session = self.create_ftrack_session()
except Exception: # noqa
self.log.warning("Couldn't create ftrack session.", exc_info=True)
return

asset = session.query(
f"Asset where parent.id is '{asset_ftrack_id}'"
f" and latest_version.task.name is '{task_name}'"
f" and name like '%{asset_name}%'"
).first()

if asset:
return asset["latest_version"]["version"]

return None

def get_ftrack_url(self):
"""Resolved ftrack url.

Expand Down
37 changes: 37 additions & 0 deletions openpype/pipeline/latest_tracked_version_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import logging

from openpype.pipeline.context_tools import _get_modules_manager as get_modules_manager
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)



log = logging.getLogger(__name__)


def get_latest_tracked_version_number(instance, task_name):
"""Get the latest version of the instance on the active tracker else None.
Args:
instance (dict): The instance whose version is to be retrieved.
task_name (str): Name of the instance's task.
"""
version_number = None
modules_manager = get_modules_manager()

# Tracker modules
ftrack_module = modules_manager.modules_by_name.get("ftrack")
kitsu_module = modules_manager.modules_by_name.get("kitsu")

if ftrack_module and ftrack_module.enabled:
asset_name = instance.data["subset"]
asset_ftrack_id = instance.data["assetEntity"]["data"].get("ftrackId")
version_number = (
ftrack_module.get_asset_latest_version_number(
asset_ftrack_id,
task_name,
asset_name
)
)
elif kitsu_module and kitsu_module.enabled:
# TODO: add support for Kitsu
pass
# Add additional tracker support here

return version_number
22 changes: 21 additions & 1 deletion openpype/plugins/publish/collect_anatomy_instance_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
get_asset_name_identifier,
)
from openpype.pipeline.version_start import get_versioning_start
from openpype.pipeline.latest_tracked_version_number import get_latest_tracked_version_number
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (93 > 79 characters)



class CollectAnatomyInstanceData(pyblish.api.ContextPlugin):
Expand Down Expand Up @@ -211,10 +212,29 @@ def fill_anatomy_data(self, context):
if version_number is None:
version_number = instance.data.get("version")

# use latest version (+1) if already any exist
if version_number is None:
# Try using the latest version data
latest_version = instance.data["latestVersion"]

if version_number is None:
# Last attempt to get the correct version number
# using the data on the tracker

# Firstly, get the task name
task_name = instance.data.get("task")
if not task_name:
task_data = anatomy_data.get("task") or {}
task_name = task_data.get("name")

# Try getting the latest version
version_number = get_latest_tracked_version_number(
instance,
task_name
)

if latest_version is not None:
# We found the latest version
# Increment the value
version_number = int(latest_version) + 1

# If version is not specified for instance or context
Expand Down
Loading