diff --git a/src/containerapp/HISTORY.rst b/src/containerapp/HISTORY.rst index 0ce871a675d..cdb096c8d97 100644 --- a/src/containerapp/HISTORY.rst +++ b/src/containerapp/HISTORY.rst @@ -2,6 +2,10 @@ Release History =============== +Upcoming +++++++ +* Fix for 'az containerapp dapr enable' cli command resulting in 'TypeError: 'NoneType' object does not support item assignment' exception. + 0.3.21 ++++++ * Fix the PermissionError caused for the Temporary files while running `az containerapp up` command on Windows diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index 139c22c797d..1a1222c9b21 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -2366,10 +2366,13 @@ def enable_dapr(cmd, name, resource_group_name, if 'configuration' not in containerapp_def['properties']: containerapp_def['properties']['configuration'] = {} - if 'dapr' not in containerapp_def['properties']['configuration']: - containerapp_def['properties']['configuration']['dapr'] = {} + if not safe_get(containerapp_def, "properties", "configuration", "dapr"): + if "dapr" not in containerapp_def['properties']['configuration']: + safe_get(containerapp_def, "properties", "configuration", "dapr", default=[]) - if dapr_app_id: + if not safe_get(containerapp_def, "properties", "configuration", "dapr", "appId"): + if dapr_app_id not in safe_get(containerapp_def['properties']['configuration']['dapr'], default=[]): + containerapp_def['properties']['configuration']['dapr']['appId'] = {} containerapp_def['properties']['configuration']['dapr']['appId'] = dapr_app_id if dapr_app_port: diff --git a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py index 142e9ac2681..55dff498a68 100644 --- a/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py +++ b/src/containerapp/azext_containerapp/tests/latest/test_containerapp_commands.py @@ -615,7 +615,7 @@ def test_containerapp_dapr_e2e(self, resource_group): JMESPathCheck('logLevel', "warn"), JMESPathCheck('enableApiLogging', True), ]) - + self.cmd('containerapp show -g {} -n {}'.format(resource_group, ca_name), checks=[ JMESPathCheck('properties.configuration.dapr.appId', "containerapp1"), JMESPathCheck('properties.configuration.dapr.appPort', 80), @@ -649,6 +649,34 @@ def test_containerapp_dapr_e2e(self, resource_group): JMESPathCheck('properties.configuration.dapr.enableApiLogging', True), ]) + @AllowLargeResponse(8192) + @ResourceGroupPreparer(location="eastus2") + def test_containerapp_up_dapr_e2e(self, resource_group): + """ Ensure that dapr can be enabled if the app has been created using containerapp up """ + location = os.getenv("CLITestLocation") + if not location: + location = 'eastus' + + self.cmd('configure --defaults location={}'.format(location)) + + image = 'mcr.microsoft.com/azuredocs/aks-helloworld:v1' + env_name = self.create_random_name(prefix='containerapp-env', length=24) + ca_name = self.create_random_name(prefix='containerapp', length=24) + + create_containerapp_env(self, env_name, resource_group) + + self.cmd( + 'containerapp up -g {} -n {} --environment {} --image {}'.format( + resource_group, ca_name, env_name, image)) + + self.cmd( + 'containerapp dapr enable -g {} -n {} --dapr-app-id containerapp1 --dapr-app-port 80 ' + '--dapr-app-protocol http --dal --dhmrs 6 --dhrbs 60 --dapr-log-level warn'.format( + resource_group, ca_name, env_name), checks=[ + JMESPathCheck('appId', "containerapp1"), + JMESPathCheck('enabled', True) + ]) + class ContainerappEnvStorageTests(ScenarioTest): @AllowLargeResponse(8192)