Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing parameter as JSON to "az policy assignment create" results in "AttributeError: 'str' object has no attribute 'get'" #55

Open
bebound opened this issue Feb 27, 2023 · 1 comment

Comments

@bebound
Copy link
Owner

bebound commented Feb 27, 2023

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az policy assignment create

Errors:

The command failed with an unexpected error. Here is the traceback:
('Unable to build a model: (\'Unable to deserialize response data. Data: {\\\'allowedContainerImagesRegex\\\': \\\'asdasd\\\'}, {ParameterValuesValue}, DeserializationError: ("Unable to deserialize to object: type, AttributeError: \\\'str\\\' object has no attribute \\\'get\\\'", AttributeError("\\\'str\\\' object has no attribute \\\'get\\\'"))\', DeserializationError("Unable to deserialize to object: type, AttributeError: \'str\' object has no attribute \'get\'", AttributeError("\'str\' object has no attribute \'get\'"))), DeserializationError: (\'Unable to deserialize response data. Data: {\\\'allowedContainerImagesRegex\\\': \\\'asdasd\\\'}, {ParameterValuesValue}, DeserializationError: ("Unable to deserialize to object: type, AttributeError: \\\'str\\\' object has no attribute \\\'get\\\'", AttributeError("\\\'str\\\' object has no attribute \\\'get\\\'"))\', DeserializationError("Unable to deserialize to object: type, AttributeError: \'str\' object has no attribute \'get\'", AttributeError("\'str\' object has no attribute \'get\'")))', DeserializationError('Unable to deserialize response data. Data: {\'allowedContainerImagesRegex\': \'asdasd\'}, {ParameterValuesValue}, DeserializationError: ("Unable to deserialize to object: type, AttributeError: \'str\' object has no attribute \'get\'", AttributeError("\'str\' object has no attribute \'get\'"))', DeserializationError("Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'", AttributeError("'str' object has no attribute 'get'"))))
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1436, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1201, in rest_key_case_insensitive_extractor
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1230, in attribute_key_case_insensitive_extractor
AttributeError: 'str' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1626, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1673, in deserialize_dict
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1673, in <dictcomp>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1639, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1454, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/exceptions.py", line 51, in raise_with_traceback
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1436, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1201, in rest_key_case_insensitive_extractor
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1230, in attribute_key_case_insensitive_extractor
azure.core.exceptions.DeserializationError: ("Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'", AttributeError("'str' object has no attribute 'get'"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 622, in body
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1406, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1415, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1637, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/exceptions.py", line 51, in raise_with_traceback
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1626, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1673, in deserialize_dict
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1673, in <dictcomp>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1639, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1454, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/exceptions.py", line 51, in raise_with_traceback
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1436, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1201, in rest_key_case_insensitive_extractor
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1230, in attribute_key_case_insensitive_extractor
azure.core.exceptions.DeserializationError: ('Unable to deserialize response data. Data: {\'allowedContainerImagesRegex\': \'asdasd\'}, {ParameterValuesValue}, DeserializationError: ("Unable to deserialize to object: type, AttributeError: \'str\' object has no attribute \'get\'", AttributeError("\'str\' object has no attribute \'get\'"))', DeserializationError("Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'", AttributeError("'str' object has no attribute 'get'")))

During handling of the above exception, another exception occurred:

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 663, in execute
  File "D:\a\_work\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\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/custom.py", line 2262, in create_policy_assignment
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/core/tracing/decorator.py", line 73, in wrapper_use_tracer
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/mgmt/resource/policy/v2021_06_01/operations/_operations.py", line 1845, in create
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 624, in body
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/exceptions.py", line 51, in raise_with_traceback
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 622, in body
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1406, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1415, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1637, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/exceptions.py", line 51, in raise_with_traceback
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1626, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1673, in deserialize_dict
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1673, in <dictcomp>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1639, in deserialize_data
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1454, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/exceptions.py", line 51, in raise_with_traceback
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1436, in _deserialize
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1201, in rest_key_case_insensitive_extractor
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msrest/serialization.py", line 1230, in attribute_key_case_insensitive_extractor
azure.core.exceptions.SerializationError: ('Unable to build a model: (\'Unable to deserialize response data. Data: {\\\'allowedContainerImagesRegex\\\': \\\'asdasd\\\'}, {ParameterValuesValue}, DeserializationError: ("Unable to deserialize to object: type, AttributeError: \\\'str\\\' object has no attribute \\\'get\\\'", AttributeError("\\\'str\\\' object has no attribute \\\'get\\\'"))\', DeserializationError("Unable to deserialize to object: type, AttributeError: \'str\' object has no attribute \'get\'", AttributeError("\'str\' object has no attribute \'get\'"))), DeserializationError: (\'Unable to deserialize response data. Data: {\\\'allowedContainerImagesRegex\\\': \\\'asdasd\\\'}, {ParameterValuesValue}, DeserializationError: ("Unable to deserialize to object: type, AttributeError: \\\'str\\\' object has no attribute \\\'get\\\'", AttributeError("\\\'str\\\' object has no attribute \\\'get\\\'"))\', DeserializationError("Unable to deserialize to object: type, AttributeError: \'str\' object has no attribute \'get\'", AttributeError("\'str\' object has no attribute \'get\'")))', DeserializationError('Unable to deserialize response data. Data: {\'allowedContainerImagesRegex\': \'asdasd\'}, {ParameterValuesValue}, DeserializationError: ("Unable to deserialize to object: type, AttributeError: \'str\' object has no attribute \'get\'", AttributeError("\'str\' object has no attribute \'get\'"))', DeserializationError("Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'", AttributeError("'str' object has no attribute 'get'"))))

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here...
  • az policy assignment create --name "restrict-container-registries" --scope "/subscriptions/subscription-id/resourceGroups/rg-demo" --policy "febd0533-8e55-448f-b837-bd0e06f16469" --params "{'allowedContainerImagesRegex': 'asdasd'}"

Expected Behavior

Azure CLI command successfully passes the argument as JSON to the Azure Policy.

Environment Summary

Windows-10-10.0.22000-SP0
Python 3.10.8
Installer: MSI

azure-cli 2.45.0

Extensions:
costmanagement 0.2.1

Dependencies:
msal 1.20.0
azure-mgmt-resource 21.1.0b1

Additional Context

The same issue occurs if I pass the json as file

az policy assignment create --name "restrict-container-registries" --scope "/subscriptions/xxx/resourceGroups/rg-demo" --policy "febd0533-8e55-448f-b837-bd0e06f16469" --params "C:\temp\params.json"

params.json

{
    "excludedNamespaces": [
        "kube-system",
        "gatekeeper-system",
        "azure-arc",
        "playground"
    ],
    "allowedContainerImagesRegex": "asdfadf\\.azurecr\\.io\/.+$",
    "effect": "Deny"
}
  • Executed the command in PowerShell 7.2.9
Name                           Value
----                           -----
PSVersion                      7.2.9
PSEdition                      Core
GitCommitId                    7.2.9
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Copy from https://github.com/Azure/azure-cli/issues/25522

@similar-bot-test
Copy link

Find similar issue https://github.com/Azure/azure-cli/issues/14501.

Issue title Struggling to assign policy to resource group with parameters.
Create time 2020-07-23
Comment number 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant