Skip to content

Commit

Permalink
fix issue with version strings failing parsing. add more unit test co…
Browse files Browse the repository at this point in the history
…verage for failing cases (#443)
  • Loading branch information
saikonen authored Oct 7, 2024
1 parent d24ee48 commit ea0bbba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions services/metadata_service/tests/unit_tests/task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@
(["2.2.12"], False),
(["metaflow_version:0.5"], False),
(["metaflow_version:1.13"], False),
(["metaflow_version:1"], False),
(["metaflow_version:1.14.0"], True),
(["metaflow_version:1.22.1"], True),
(["metaflow_version:2.0.0"], False),
(["metaflow_version:2.0"], False),
(["metaflow_version:2"], False),
(["metaflow_version:2.0.5"], False),
(["metaflow_version:2.2.11"], False),
(["metaflow_version:2.2.12"], True),
(["metaflow_version:2.2.12+ab1234"], True),
(["metaflow_version:2.3"], True),
(["metaflow_version:2.3.1"], True),
(["metaflow_version:2.4.1"], True),
(["metaflow_version:2.12.24.post9-git2a5367b+ob(v1)"], True),
(["metaflow_version:2.12.24+inconsequential+trailing-string"], True),
(["metaflow_version:2.12.24.break"], True),
(["metaflow_version:3"], True),
]


Expand Down
10 changes: 7 additions & 3 deletions services/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import re
import sys
import os
import traceback
Expand All @@ -13,7 +14,6 @@
from packaging.version import Version, parse
from importlib import metadata


USE_SEPARATE_READER_POOL = os.environ.get("USE_SEPARATE_READER_POOL", "0") in ["True", "true", "1"]

version = metadata.version("metadata_service")
Expand Down Expand Up @@ -149,8 +149,12 @@ def format_baseurl(request: web.BaseRequest):
def has_heartbeat_capable_version_tag(system_tags):
"""Check client version tag whether it is known to support heartbeats or not"""
try:
version_tags = [tag for tag in system_tags if tag.startswith('metaflow_version:')]
version = parse(version_tags[0][17:])
# only parse for the major.minor.patch version and disregard any trailing bits that might cause issues with comparison.
version_tag = [tag for tag in system_tags if tag.startswith('metaflow_version:')][0]
# match versions: major | major.minor | major.minor.patch
ver_string = re.match(r"(0|\d+)(\.(0|\d+))*", version_tag[len("metaflow_version:"):])[0]
print(ver_string)
version = parse(ver_string)

if version >= Version("1") and version < Version("2"):
return version >= Version("1.14.0")
Expand Down

0 comments on commit ea0bbba

Please sign in to comment.