Skip to content

Commit 024cfb6

Browse files
mattboentoroMatthew Boentoro
andauthored
{RDBMS} az postgres flexible-server create: Fix the comparator for sorting sku name so it also sort the core number too when displaying the error message (#30582)
Co-authored-by: Matthew Boentoro <[email protected]>
1 parent 77e4d7e commit 024cfb6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/azure-cli/azure/cli/command_modules/rdbms/validators.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,24 @@ def _pg_tier_validator(tier, sku_info):
453453

454454

455455
def compare_sku_names(sku_1, sku_2):
456-
regex_pattern = r"_v(\d)"
456+
regex_pattern = r"\D+(?P<core_number>\d+)\D+(?P<version>\d*)"
457457

458458
sku_1_match = re.search(regex_pattern, sku_1)
459459
sku_2_match = re.search(regex_pattern, sku_2)
460460

461-
return (int(sku_2_match.group(1)) if sku_2_match else 0) - \
462-
(int(sku_1_match.group(1)) if sku_1_match else 0)
461+
# the case where version number is different, sort by the version number first
462+
if sku_1_match.group('version') and int(sku_2_match.group('version')) > int(sku_1_match.group('version')):
463+
return 1
464+
if sku_1_match.group('version') and int(sku_2_match.group('version')) < int(sku_1_match.group('version')):
465+
return -1
466+
467+
# the case where version number is the same, we want to sort by the core number
468+
if int(sku_2_match.group('core_number')) > int(sku_1_match.group('core_number')):
469+
return 1
470+
if int(sku_2_match.group('core_number')) < int(sku_1_match.group('core_number')):
471+
return -1
472+
473+
return 0
463474

464475

465476
def _pg_sku_name_validator(sku_name, sku_info, tier, instance):

0 commit comments

Comments
 (0)