Azure / azure-cli

Azure Command-Line Interface
MIT License
3.95k stars 2.93k forks source link

az lock create , On sql database causes error #23218

Open Maashkinoozhe opened 2 years ago

Maashkinoozhe commented 2 years ago

Describe the bug

I tried to create a cannotdeletelock on an sql database.

It works with Powershell New-AzResourceLock but not with azure cli.

Command Name az lock create

Errors:

The command failed with an unexpected error. Here is the traceback:
No value for given attribute
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/custom.py", line 3231, in create_lock
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/core/tracing/decorator.py", line 73, in wrapper_use_tracer
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/mgmt/resource/locks/v2016_09_01/operations/_operations.py", line 1198, in create_or_update_at_resource_level
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/mgmt/resource/locks/v2016_09_01/operations/_operations.py", line 291, in build_management_locks_create_or_update_at_resource_level_request
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 652, in url
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 760, in serialize_data
ValueError: No value for given attribute

To Reproduce:

Use this command with an existing sql database.

Expected Behavior

Creates a lock on the sql db

Environment Summary

Windows-10-10.0.19044-SP0
Python 3.10.5
Installer: MSI

azure-cli 2.38.0

Extensions:
azure-devops 0.25.0

Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1

Additional Context

yonzhan commented 2 years ago

ARM

ghost commented 2 years ago

Thank you for your feedback. This has been routed to the support team for assistance.

hde-celum commented 9 months ago

Any news on this ?

glebteterin commented 8 months ago

I got the same error but managed to find the correct combination of parameters:

az lock create --lock-type CanNotDelete --name DeleteLock --notes "your note here" --namespace Microsoft.Sql/servers/[server_name] --resource-type databases --resource-group [resource_group_name] --resource [database_name]

Just replace [server_name], [resource_group_name] and [database_name] with real values