diff --git a/src/azure-cli/HISTORY.rst b/src/azure-cli/HISTORY.rst index f091f159e11..a187ad4d135 100644 --- a/src/azure-cli/HISTORY.rst +++ b/src/azure-cli/HISTORY.rst @@ -74,6 +74,7 @@ Release History * `az postgres flexible-server backup create`: Fix duplicate auto-generated backup names after deletions (#33684) * `az postgres flexible-server create`: Add example to create elastic cluster with custom database name (#33712) * `az postgres flexible-server upgrade`: Introduced `--validate-only` param for PVC (#33683) +* `az postgres flexible-server maintenance-event list`: Fix `TypeError` caused by an unsupported `--ids` argument (#33846) 2.88.0 ++++++ diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/_params.py b/src/azure-cli/azure/cli/command_modules/postgresql/_params.py index b65320e55b4..117daad37b2 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/_params.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/_params.py @@ -685,6 +685,7 @@ def _flexible_server_params(command_group): with self.argument_context('{} flexible-server maintenance-event list'.format(command_group)) as c: c.argument('maintenance_status', arg_type=maintenance_status_arg_type) + c.argument('server_name', arg_type=server_name_resource_arg_type, id_part=None) c.ignore('ids') for scope in ['show', 'reschedule', 'apply-now']: diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_maintenance_event_params.py b/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_maintenance_event_params.py new file mode 100644 index 00000000000..ba49abf8ae2 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_maintenance_event_params.py @@ -0,0 +1,56 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import unittest +from unittest import mock + +from knack.arguments import IgnoreAction +from azure.cli.core.mock import DummyCli +from azure.cli.command_modules.postgresql import PostgreSQLCommandsLoader + + +def _load_command_and_arguments(command): + """Load the PostgreSQL command loader for *command* and return the loader.""" + cli = DummyCli(commands_loader_cls=PostgreSQLCommandsLoader) + loader = PostgreSQLCommandsLoader(cli) + cli.invocation = mock.MagicMock() + cli.invocation.commands_loader = loader + loader.command_name = command + loader.load_command_table(None) + loader.load_arguments(command) + loader._update_command_definitions() + return loader + + +class MaintenanceEventParamsTest(unittest.TestCase): + """Regression test for https://github.com/Azure/azure-cli/issues/33846. + + `az postgres flexible-server maintenance-event list` does not accept an `ids` + keyword argument in its custom command implementation, so the auto-generated + `--ids` argument must be ignored for that command. Otherwise, invoking the + command with `--ids` results in a TypeError. + """ + + def test_maintenance_event_list_ignores_ids(self): + """The ``ids`` argument for the list command must use IgnoreAction.""" + loader = _load_command_and_arguments( + 'postgres flexible-server maintenance-event list' + ) + ids_arg = loader.argument_registry.arguments.get( + 'postgres flexible-server maintenance-event list', {} + ).get('ids') + self.assertIsNotNone(ids_arg, "'ids' argument not found in argument registry") + action = ids_arg.settings.get('action') + self.assertIs( + action, + IgnoreAction, + "Expected 'ids' to be registered with IgnoreAction (via c.ignore('ids')), " + "but got: {}".format(action), + ) + + +if __name__ == '__main__': + unittest.main() +