Skip to content

register_argument_deprecate doesn't work with boolean or switch parameters #31293

@ArulvelMuralidharan

Description

@ArulvelMuralidharan

Describe the bug

There seems to be a bug with the register_argument_deprecate function https://github.com/Azure/azure-cli/blob/dev/doc/how_to_introduce_breaking_changes.md where when a parameter is passed in that is a boolean or switch parameter, it errors out during runtime when executing the command itself.

I followed the steps and creating a _breaking_change.py file and added the function register_argument_deprecate('aksarc create', '--enable-ahub') to deprecate the enable-ahub parameter.

However, when I do this, I get an error when executing any of the az aksarc create commands. It works while building but fails when I build the extension and try to run the az aksarc create command.

However, when I use other parameters like --name which are not booleans/switches for the register_argument_deprecate function then it works and I can properly see the warning when executing the command.

Related command

register_argument_deprecate('aksarc create', '--enable-ahub')

I build the code and run az extension add --source

And when I run az aksarc create I get an error. It doesn't matter what parameters I provide, even if I don't pass in the parameter I passed to register_argument_deprecate it still fails.

Errors

az aksarc create
D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/backends/openssl/backend.py:8: UserWarning: You are using cryptography on a 32-bit Python on a 64-bit Windows Operating System. Cryptography will be significantly faster if you switch to using a 64-bit Python.
The command failed with an unexpected error. Here is the traceback:
'AzCliCommandInvoker' object has no attribute 'command_loader'
Traceback (most recent call last):
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 566, in execute
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 170, in raise_event
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 539, in update_breaking_change_info
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 249, in register
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 33, in _argument_breaking_change_action
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 27, in _get_action_class
AttributeError: 'AzCliCommandInvoker' object has no attribute 'command_loader'. Did you mean: 'commands_loader'?

Issue script & Debug output

az aksarc create --debug
cli.knack.cli: Command arguments: ['aksarc', 'create', '--debug']
cli.knack.cli: init debug log:
Enable color in terminal.
Enable VT mode.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x01682938>, <function OutputProducer.on_global_arguments at 0x017C4528>, <function CLIQuery.on_global_arguments at 0x017E2028>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'aksarc': ['azext_aksarc']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: Total (0) 0.000 0 0
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: aksarc 0.451 6 25 C:\Users\akshciuser.azure\cliextensions\aksarc
cli.azure.cli.core: Total (1) 0.451 6 25
cli.azure.cli.core: Loaded 6 groups, 25 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : aksarc create
cli.azure.cli.core: Command table: aksarc create
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x0374A398>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\akshciuser.azure\commands\2025-04-17.15-45-55.aksarc_create.5780.log'.
az_command_data_logger: command args: aksarc create --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x0375FF28>]
D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/backends/openssl/backend.py:8: UserWarning: You are using cryptography on a 32-bit Python on a 64-bit Windows Operating System. Cryptography will be significantly faster if you switch to using a 64-bit Python.
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x037AAF78>, <function register_cache_arguments..add_cache_arguments at 0x037B4028>, <function register_upcoming_breaking_change_info..update_breaking_change_info at 0x037B4078>]
cli.azure.cli.core.azclierror: Traceback (most recent call last):
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 566, in execute
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 170, in raise_event
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 539, in update_breaking_change_info
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 249, in register
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 33, in _argument_breaking_change_action
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 27, in _get_action_class
AttributeError: 'AzCliCommandInvoker' object has no attribute 'command_loader'. Did you mean: 'commands_loader'?

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
cli.azure.cli.core.azclierror: 'AzCliCommandInvoker' object has no attribute 'command_loader'
Traceback (most recent call last):
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 566, in execute
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 170, in raise_event
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 539, in update_breaking_change_info
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 249, in register
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 33, in _argument_breaking_change_action
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 27, in _get_action_class
AttributeError: 'AzCliCommandInvoker' object has no attribute 'command_loader'. Did you mean: 'commands_loader'?
az_command_data_logger: 'AzCliCommandInvoker' object has no attribute 'command_loader'
Traceback (most recent call last):
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 566, in execute
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 170, in raise_event
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 539, in update_breaking_change_info
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 249, in register
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 33, in _argument_breaking_change_action
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/breaking_change.py", line 27, in get_action_class
AttributeError: 'AzCliCommandInvoker' object has no attribute 'command_loader'. Did you mean: 'commands_loader'?
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x0374A4D8>]
az_command_data_logger: exit code: 1
cli.main: Command ran in 1.497 seconds (init: 0.305, invoke: 1.192)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 7633 in cache file under C:\Users\akshciuser.azure\telemetry\20250417154556336
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\telemetry_init
.pyc C:\Users\akshciuser.azure C:\Users\akshciuser.azure\telemetry\20250417154556336"
telemetry.process: Return from creating process 7196
telemetry.main: Finish creating telemetry upload process.

Expected behavior

The command should display the warning like so when run

Option '--enable-ahub' has been deprecated and will be removed in next breaking change release(2.73.0).

Environment Summary

az --version
azure-cli 2.69.0 *

core 2.69.0 *
telemetry 1.1.0

Extensions:
aksarc 0.9.0 (Using a version built locally, I am trying to deprecate a parameter)
arcappliance 1.4.0
connectedk8s 1.10.6
customlocation 0.1.3
k8s-extension 1.6.4
stack-hci-vm 1.6.5

Dependencies:
msal 1.31.2b1
azure-mgmt-resource 23.1.1

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Config directory 'C:\Users\akshciuser.azure'
Extensions directory 'C:\Users\akshciuser.azure\cliextensions'

Python (Windows) 3.12.8 (tags/v3.12.8:2dc476b, Dec 3 2024, 19:07:15) [MSC v.1942 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Auto-ResolveAuto resolve by botService AttentionThis issue is responsible by Azure service team.Similar-IssuebugThis issue requires a change to an existing behavior in the product in order to be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions