Skip to content

Commit

Permalink
Pad version with zero if shorter than 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jingcheng16 committed Dec 18, 2024
1 parent b99aa51 commit e34b249
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions corehq/apps/builds/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def test_is_out_of_date(self):
('2.53.1', 'invalid', False), # Invalid latest version
('6', '7', True), # Normal case - app version is integer
(None, None, False), # None version_in_use and latest_version
('2.54', '2.54.0', False), # Edge case - should not be out of date
('2.54.0', '2.54', False), # Edge case - should not be out of date
]

for version_in_use, latest_version, expected in test_cases:
Expand Down
7 changes: 5 additions & 2 deletions corehq/apps/builds/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ def is_out_of_date(version_in_use, latest_version):


def _parse_version(version_str):
"""Convert version string to comparable tuple"""
"""Convert version string to comparable tuple, padding with zeros."""
SEMANTIC_VERSION_PARTS = 3 # Major, minor, patch
if version_str:
try:
return tuple(int(n) for n in version_str.split('.'))
version_parts = [int(n) for n in version_str.split('.')]
# Pad the version tuple to ensure both versions have the same length
return tuple(version_parts + [0] * (SEMANTIC_VERSION_PARTS - len(version_parts)))
except (ValueError, AttributeError):
return None
return None

0 comments on commit e34b249

Please sign in to comment.