Skip to content

Commit 983134b

Browse files
authored
[ARM] Fix az resource list cannot use tag when there is a default location (#11787)
* Improve the error message of the conflict between tag and other filter conditions for az resource list
1 parent 55a0a0d commit 983134b

File tree

4 files changed

+768
-3
lines changed

4 files changed

+768
-3
lines changed

src/azure-cli/HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Release History
2525

2626
* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters
2727
* Fix issue #10279: The exit code of `az group deployment validate` is 0 when the verification fails
28+
* Fix issue #9916: Improve the error message of the conflict between tag and other filter conditions for `az resource list` command
2829

2930
**Azure Red Hat OpenShift**
3031

src/azure-cli/azure/cli/command_modules/resource/custom.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,20 @@ def _deploy_arm_template_subscription_scope(cli_ctx,
510510
def _list_resources_odata_filter_builder(resource_group_name=None, resource_provider_namespace=None,
511511
resource_type=None, name=None, tag=None, location=None):
512512
"""Build up OData filter string from parameters """
513+
if tag is not None:
514+
if resource_group_name:
515+
raise IncorrectUsageError('you cannot use \'--tag\' with \'--resource-group\''
516+
'(If the default value for resource group is set, please use \'az configure --defaults group=""\' command to clear it first)')
517+
if resource_provider_namespace:
518+
raise IncorrectUsageError('you cannot use \'--tag\' with \'--namespace\'')
519+
if resource_type:
520+
raise IncorrectUsageError('you cannot use \'--tag\' with \'--resource-type\'')
521+
if name:
522+
raise IncorrectUsageError('you cannot use \'--tag\' with \'--name\'')
523+
if location:
524+
raise IncorrectUsageError('you cannot use \'--tag\' with \'--location\''
525+
'(If the default value for location is set, please use \'az configure --defaults location=""\' command to clear it first)')
526+
513527
filters = []
514528

515529
if resource_group_name:
@@ -537,9 +551,6 @@ def _list_resources_odata_filter_builder(resource_group_name=None, resource_prov
537551
raise CLIError('--namespace also requires --resource-type')
538552

539553
if tag:
540-
if name or location:
541-
raise IncorrectUsageError('you cannot use the tag filter with other filters')
542-
543554
tag_name = list(tag.keys())[0] if isinstance(tag, dict) else tag
544555
tag_value = tag[tag_name] if isinstance(tag, dict) else ''
545556
if tag_name:

0 commit comments

Comments
 (0)