Merge pull request #202 from BigRoy/bugfix/inventory_latest_version

Bugfix: Consider Hero versions correctly for checking outdated
This commit is contained in:
Jakub Trllo 2024-03-25 16:46:44 +01:00 committed by GitHub
commit 1271b74f43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 33 deletions

View file

@ -68,13 +68,7 @@ class InventoryModel(TreeModel):
}
def outdated(self, item):
value = item.get("version")
if isinstance(value, HeroVersionType):
return False
if item.get("version") == item.get("highest_version"):
return False
return True
return item.get("isOutdated", True)
def data(self, index, role):
if not index.isValid():
@ -297,6 +291,21 @@ class InventoryModel(TreeModel):
)
sites_info = self._controller.get_sites_information()
# Query the highest available version so the model can know
# whether current version is currently up-to-date.
highest_version_by_product_id = ayon_api.get_last_versions(
project_name,
product_ids={
group["version"]["productId"] for group in grouped.values()
},
fields={"productId", "version"}
)
# Map value to `version` key
highest_version_by_product_id = {
product_id: version["version"]
for product_id, version in highest_version_by_product_id.items()
}
for repre_id, group_dict in sorted(grouped.items()):
group_containers = group_dict["containers"]
repre_entity = group_dict["representation"]
@ -306,12 +315,6 @@ class InventoryModel(TreeModel):
product_type = product_entity["productType"]
# Store the highest available version so the model can know
# whether current version is currently up-to-date.
highest_version = ayon_api.get_last_version_by_product_id(
project_name, version_entity["productId"]
)
# create the group header
group_node = Item()
group_node["Name"] = "{}_{}: ({})".format(
@ -320,8 +323,23 @@ class InventoryModel(TreeModel):
repre_entity["name"]
)
group_node["representation"] = repre_id
group_node["version"] = version_entity["version"]
group_node["highest_version"] = highest_version["version"]
# Detect hero version type
version = version_entity["version"]
if version < 0:
version = HeroVersionType(version)
group_node["version"] = version
# Check if the version is outdated.
# Hero versions are never considered to be outdated.
is_outdated = False
if not isinstance(version, HeroVersionType):
last_version = highest_version_by_product_id.get(
version_entity["productId"])
if last_version is not None:
is_outdated = version_entity["version"] != last_version
group_node["isOutdated"] = is_outdated
group_node["productType"] = product_type or ""
group_node["productTypeIcon"] = product_type_icon
group_node["count"] = len(group_containers)
@ -490,27 +508,11 @@ class FilterProxyModel(QtCore.QSortFilterProxyModel):
def _is_outdated(self, row, parent):
"""Return whether row is outdated.
A row is considered outdated if it has "version" and "highest_version"
data and in the internal data structure, and they are not of an
equal value.
A row is considered outdated if `isOutdated` data is true or not set.
"""
def outdated(node):
version = node.get("version", None)
highest = node.get("highest_version", None)
# Always allow indices that have no version data at all
if version is None and highest is None:
return True
# If either a version or highest is present but not the other
# consider the item invalid.
if not self._hierarchy_view:
# Skip this check if in hierarchy view, or the child item
# node will be hidden even it's actually outdated.
if version is None or highest is None:
return False
return version != highest
return node.get("isOutdated", True)
index = self.sourceModel().index(row, self.filterKeyColumn(), parent)

View file

@ -123,6 +123,7 @@ def paint_image_with_color(image, color):
def format_version(value):
"""Formats integer to displayable version name"""
value = int(value) # convert e.g. HeroVersionType to its version value
label = "v{0:03d}".format(abs(value))
if value < 0:
return "[{}]".format(label)