Skip to content

Commit 7e501f6

Browse files
committed
LazyToolBox: use packaging.version for get_all_versions sort
The custom sort key in 75f9a52 — ``tuple(int(p) if p.isdigit() else p ...)`` — mixed ``int`` and ``str`` segments and crashed on tool versions like ``1.0.0+galaxy0`` with ``TypeError: '<' not supported between instances of 'str' and 'int'``. Two API tests on shard 0 (``test_test_by_versions``) and shard 1 (``test_job_build_for_rerun_switch_version``) hit the bug through ``Tool._compare_tool_version`` -> ``get_tool(get_all_versions=True)`` and surfaced as 500 / 400 to the API caller. Switch to ``packaging.version.parse`` (what the eager ``ToolLineage`` uses under SortedSet) and bucket unparseable versions to a string-fallback so the sort still completes if one entry is malformed.
1 parent 75f9a52 commit 7e501f6

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/galaxy/tools/lazy_toolbox.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,20 @@ def get_tool(
11401140
# refactor's ``upgrade_all_steps``) need every version to
11411141
# determine the latest; returning only the requested version
11421142
# makes upgrades silently no-op.
1143+
# Lazy import: ``packaging.version.parse`` matches what the
1144+
# eager ToolLineage uses to order versions and tolerates
1145+
# non-numeric segments (e.g. ``"1.0.0+galaxy0"``).
1146+
from packaging.version import parse as _parse_version
1147+
1148+
def _ver_key(v: str):
1149+
try:
1150+
return (0, _parse_version(v))
1151+
except Exception:
1152+
return (1, v)
1153+
11431154
versions = sorted(
11441155
self._tool_index.entries_by_version.get(tool_id, {}).keys(),
1145-
key=lambda v: tuple(int(p) if p.isdigit() else p for p in v.split(".") if p),
1156+
key=_ver_key,
11461157
)
11471158
tools: list["Tool"] = []
11481159
for ver in versions:

0 commit comments

Comments
 (0)