From 7c1282d0f4b3811baed8314777089f38408ca94e Mon Sep 17 00:00:00 2001 From: Prathamesh Hukkeri Date: Tue, 28 Jul 2026 10:59:18 +0530 Subject: [PATCH] fix(api): use numeric version sorting for artifact versions The previous implementation used lexicographic sorting for version URLs, which produces incorrect results for semver-style version IDs: Lexicographic: ['2.9.0', '2.10.0', '2.1.0'] -> '2.9.0' (wrong) Numeric: ['2.10.0', '2.9.0', '2.1.0'] -> '2.10.0' (correct) This fix extracts the version segment from each URL and parses it as a numeric tuple for proper semantic version comparison. Falls back to lexicographic comparison for non-standard formats. Fixes #70 --- databusclient/api/download.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/databusclient/api/download.py b/databusclient/api/download.py index ad7d76e..7542c1a 100644 --- a/databusclient/api/download.py +++ b/databusclient/api/download.py @@ -880,7 +880,24 @@ 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 + def _version_key(url: str) -> tuple: + """Extract version segment from URL and parse as numeric tuple for sorting. + + Handles semver-style versions (e.g., 2.10.0 > 2.9.0) by comparing + numeric segments. Falls back to lexicographic comparison for + non-standard formats. + """ + segment = url.rstrip("/").split("/")[-1] + try: + # Split on dots and convert each part to int for numeric comparison + parts = tuple(int(p) for p in segment.split(".")) + return parts + except (ValueError, AttributeError): + # Fallback for non-numeric versions (e.g., date-based: 2022.12.01) + # Prefix with (0,) to sort after numeric versions + return (0, segment) + + version_urls.sort(key=_version_key, reverse=True) # Sort versions in descending order if all_versions: return version_urls