From 0772a0618fe80534ee6114ba38e1f7c4189ec474 Mon Sep 17 00:00:00 2001 From: Harshitha Akkaraju Date: Tue, 19 May 2026 21:21:28 -0700 Subject: [PATCH] [App Service] `az functionapp deployment source config-zip`: Fix KeyError 'FUNCTIONS_WORKER_RUNTIME' for Go on Flex Consumption Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../cli/command_modules/appservice/custom.py | 2 +- .../test_functionapp_commands_thru_mock.py | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/custom.py b/src/azure-cli/azure/cli/command_modules/appservice/custom.py index 6eac25c36ab..1d335e960ca 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/custom.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/custom.py @@ -7768,7 +7768,7 @@ def _parse_raw_stacks(self, stacks): continue runtime_settings = minor_version['stackSettings']['linuxRuntimeSettings'] - runtime_name = (runtime_settings['appSettingsDictionary']['FUNCTIONS_WORKER_RUNTIME'] or + runtime_name = (runtime_settings.get('appSettingsDictionary', {}).get('FUNCTIONS_WORKER_RUNTIME') or runtime['name']) skus = runtime_settings['Sku'] diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_functionapp_commands_thru_mock.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_functionapp_commands_thru_mock.py index 9f766ab8e2b..09118278518 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_functionapp_commands_thru_mock.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_functionapp_commands_thru_mock.py @@ -681,3 +681,62 @@ def test_config_source_control(self, # assert self.assertEqual(response.git_hub_action_configuration.container_configuration.password, None) + + def test_flex_parse_raw_stacks_handles_empty_app_settings_dictionary(self): + from azure.cli.command_modules.appservice.custom import _FlexFunctionAppStackRuntimeHelper + + # prepare + cmd_mock = _get_test_cmd() + go_stack = { + 'name': 'go', + 'properties': {'majorVersions': [{'minorVersions': [{ + 'value': '1.0', + 'stackSettings': {'linuxRuntimeSettings': { + 'appSettingsDictionary': {}, + 'Sku': [{'skuCode': 'FC1'}], + 'gitHubActionSettings': {'isSupported': True}, + 'appInsightsSettings': {'isSupported': True}, + 'isDefault': True, + }}, + }]}]}, + } + + # action + with mock.patch.object(_FlexFunctionAppStackRuntimeHelper, + 'get_flex_raw_function_app_stacks', + return_value=[go_stack]): + matched = _FlexFunctionAppStackRuntimeHelper(cmd_mock, 'westcentralus', 'go').resolve('go', '1.0') + + # assert + self.assertEqual(matched.name, 'go') + self.assertEqual(matched.version, '1.0') + + def test_flex_parse_raw_stacks_prefers_functions_worker_runtime_when_present(self): + # FUNCTIONS_WORKER_RUNTIME overrides runtime['name'] when set (e.g., dotnet-isolated under the dotnet stack). + from azure.cli.command_modules.appservice.custom import _FlexFunctionAppStackRuntimeHelper + + # prepare + cmd_mock = _get_test_cmd() + dotnet_isolated_stack = { + 'name': 'dotnet', + 'properties': {'majorVersions': [{'minorVersions': [{ + 'value': '8.0', + 'stackSettings': {'linuxRuntimeSettings': { + 'appSettingsDictionary': {'FUNCTIONS_WORKER_RUNTIME': 'dotnet-isolated'}, + 'Sku': [{'skuCode': 'FC1'}], + 'gitHubActionSettings': {'isSupported': True}, + 'appInsightsSettings': {'isSupported': True}, + 'isDefault': True, + }}, + }]}]}, + } + + # action + with mock.patch.object(_FlexFunctionAppStackRuntimeHelper, + 'get_flex_raw_function_app_stacks', + return_value=[dotnet_isolated_stack]): + matched = _FlexFunctionAppStackRuntimeHelper( + cmd_mock, 'westcentralus', 'dotnet-isolated').resolve('dotnet-isolated', '8.0') + + # assert + self.assertEqual(matched.name, 'dotnet-isolated')