From b17b7fdad58f31538c3b362c54a769075e43690e Mon Sep 17 00:00:00 2001 From: Prakhar54-byte Date: Mon, 6 Jul 2026 02:06:01 +0530 Subject: [PATCH] fix(download): use numeric sort key for artifact version URLs version_urls.sort(reverse=True) performs a plain lexicographic sort, which returns the wrong 'latest' version for semver-style IDs: ['2.10.0', '2.9.0'] -> lexicographic latest is '2.9.0' (wrong) Add _parse_version_key() which splits the trailing URL segment on non-digit characters and compares each part as an integer, giving correct numeric ordering with no new dependencies (re is stdlib). Date-style versions (2022.12.01) continue to work correctly. Closes # --- databusclient/api/download.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/databusclient/api/download.py b/databusclient/api/download.py index 312af45..de4744c 100644 --- a/databusclient/api/download.py +++ b/databusclient/api/download.py @@ -844,6 +844,18 @@ def _download_artifact( ) +def _parse_version_key(url: str) -> tuple: + """Return a numeric sort key derived from the version segment of a Databus URL. + + Splits the trailing version segment by non-digit characters and compares each + part as an integer, so '2.10.0' correctly sorts after '2.9.0' (unlike plain + lexicographic sort where '2.9' > '2.10' as strings). + """ + segment = url.rstrip("/").split("/")[-1] + parts = re.split(r"[^0-9]+", segment) + return tuple(int(p) for p in parts if p.isdigit()) + + def _get_databus_versions_of_artifact( json_str: str, all_versions: bool ) -> str | List[str]: @@ -875,7 +887,7 @@ def _get_databus_versions_of_artifact( if not version_urls: raise ValueError("No versions found in artifact JSON-LD") - version_urls.sort(reverse=True) # Sort versions in descending order + version_urls.sort(key=_parse_version_key, reverse=True) if all_versions: return version_urls