From 022f049bfcf86609daf0c2d9ddc0b1c108b9ea7c Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Wed, 19 Jun 2024 09:39:22 +0200 Subject: [PATCH] CLI: Fix bug with profile name determination in `verdi presto` (#6477) When the user is using `verdi presto` to create more than 11 profiles, the command will fail because `presto-10` already exists. This is due to the fact that the `get_default_presto_profile_name()` function sorts the existing indices as strings, which means `10` will precede `9` and hence the "last index" would be `9`, making the new index `10`, which already exists. Here we fix this issue by casting the extracted existing indices as integers, so the sorting works as intended. --- src/aiida/cmdline/commands/cmd_presto.py | 2 +- tests/cmdline/commands/test_presto.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/aiida/cmdline/commands/cmd_presto.py b/src/aiida/cmdline/commands/cmd_presto.py index b61a8b6cfd..1893a6d461 100644 --- a/src/aiida/cmdline/commands/cmd_presto.py +++ b/src/aiida/cmdline/commands/cmd_presto.py @@ -32,7 +32,7 @@ def get_default_presto_profile_name(): for profile_name in profile_names: if match := re.search(r'presto[-]?(\d+)?', profile_name): - indices.append(match.group(1) or '0') + indices.append(int(match.group(1) or '0')) if not indices: return DEFAULT_PROFILE_NAME_PREFIX diff --git a/tests/cmdline/commands/test_presto.py b/tests/cmdline/commands/test_presto.py index 13760a53b7..8651664f61 100644 --- a/tests/cmdline/commands/test_presto.py +++ b/tests/cmdline/commands/test_presto.py @@ -80,3 +80,11 @@ def test_presto_use_postgres_fail(run_cli_command): options = ['--non-interactive', '--use-postgres', '--postgres-port', str(5000)] result = run_cli_command(verdi_presto, options, raises=True) assert 'Failed to connect to the PostgreSQL server' in result.output + + +@pytest.mark.usefixtures('empty_config') +def test_presto_overdose(run_cli_command, config_with_profile_factory): + """Test that ``verdi presto`` still works for users that have over 10 presto profiles.""" + config_with_profile_factory(name='presto-10') + result = run_cli_command(verdi_presto) + assert 'Created new profile `presto-11`.' in result.output