From 8e47dc2d359688516c699e0f922c33c021c3a1a4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:33:28 -0800 Subject: [PATCH] Fix regression in semver comparison logic (#7040) (#7041) (cherry picked from commit 915585c36e5798a8d81dbb74afde5a818b1c7803) Co-authored-by: Jeremy Cohen --- .changes/unreleased/Fixes-20230224-001338.yaml | 6 ++++++ core/dbt/semver.py | 4 ++-- test/unit/test_semver.py | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230224-001338.yaml diff --git a/.changes/unreleased/Fixes-20230224-001338.yaml b/.changes/unreleased/Fixes-20230224-001338.yaml new file mode 100644 index 00000000000..28f33bef515 --- /dev/null +++ b/.changes/unreleased/Fixes-20230224-001338.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix semver comparison logic by ensuring numeric values +time: 2023-02-24T00:13:38.23242+01:00 +custom: + Author: jtcohen6 + Issue: "7039" diff --git a/core/dbt/semver.py b/core/dbt/semver.py index d3502576122..af38340ee5a 100644 --- a/core/dbt/semver.py +++ b/core/dbt/semver.py @@ -152,9 +152,9 @@ def compare(self, other): # else is equal and will fall through else: # major/minor/patch, should all be numbers - if a > b: + if int(a) > int(b): return 1 - elif a < b: + elif int(a) < int(b): return -1 # else is equal and will fall through diff --git a/test/unit/test_semver.py b/test/unit/test_semver.py index 4deafa25360..7add2516d9e 100644 --- a/test/unit/test_semver.py +++ b/test/unit/test_semver.py @@ -200,6 +200,14 @@ def test__resolve_to_specific_version(self): ['1.0.0', '1.1.0a1', '1.1.0', '1.2.0a1', '1.2.0']), '1.1.0') + self.assertEqual( + resolve_to_specific_version( + # https://github.com/dbt-labs/dbt-core/issues/7039 + # 10 is greater than 9 + create_range('>0.9.0', '<0.10.0'), + ['0.9.0', '0.9.1', '0.10.0']), + '0.9.1') + def test__filter_installable(self): installable = filter_installable( ['1.1.0', '1.2.0a1', '1.0.0','2.1.0-alpha','2.2.0asdf','2.1.0','2.2.0','2.2.0-fishtown-beta','2.2.0-2'],