Skip to content

[App Service] az functionapp deployment source config-zip: Fix KeyError 'FUNCTIONS_WORKER_RUNTIME' for Go on Flex Consumption#33404

Open
harshivcodes wants to merge 1 commit into
Azure:devfrom
harshivcodes:fix-flex-consumption-go-fwr-keyerror
Open

[App Service] az functionapp deployment source config-zip: Fix KeyError 'FUNCTIONS_WORKER_RUNTIME' for Go on Flex Consumption#33404
harshivcodes wants to merge 1 commit into
Azure:devfrom
harshivcodes:fix-flex-consumption-go-fwr-keyerror

Conversation

@harshivcodes
Copy link
Copy Markdown

Related command
az functionapp deployment source config-zip

(Also affects every other az functionapp command that goes through _FlexFunctionAppStackRuntimeHelper: functionapp create, functionapp config set for runtime, functionapp list-flexconsumption-runtimes, functionapp list-flexconsumption-locations, functionapp deployment github-actions add, functionapp flex-migration.)

Description

az functionapp deployment source config-zip crashes with KeyError: 'FUNCTIONS_WORKER_RUNTIME' for every Go function app on Flex Consumption, before any zip is uploaded. The crash is in _FlexFunctionAppStackRuntimeHelper._parse_raw_stacks at custom.py:7771:

runtime_name = (runtime_settings['appSettingsDictionary']['FUNCTIONS_WORKER_RUNTIME'] or
                runtime['name'])

The intent is to prefer FUNCTIONS_WORKER_RUNTIME but fall back to runtime['name'] when FWR isn't set. But the dictionary access is hard-indexed instead of using .get(), so Python raises KeyError before the or fallback can execute.

This is fine for node/python/java/powershell/dotnet — their stack definitions populate appSettingsDictionary.FUNCTIONS_WORKER_RUNTIME in the API response. It breaks for Go because Flex Consumption Go apps deliberately return appSettingsDictionary: {} (Go on Flex doesn't require FWR on the app at runtime — native binaries, no managed worker). The Go stack definition isn't introducing this bug; it's exposing a latent over-assumption in the CLI parser that was hidden only because every prior Flex language happened to populate FWR.

Fix: change the chained [ ] lookup to use .get() so the existing or runtime['name'] fallback can run. This matches the defensive pattern already used by the sibling Windows/Linux helper _FunctionAppStackRuntimeHelper._parse_minor_version in the same file.

For Go, runtime['name'] resolves to "go", the stack registers as "go", and downstream resolve("go") matches the deployed app's functionAppConfig.runtime.name == "go" cleanly. Other languages are unaffected — their FWR value is truthy, so or short-circuits before the fallback.

Testing Guide

  1. Existing mock test suite still passes (25/25):
    python -m unittest azure.cli.command_modules.appservice.tests.latest.test_functionapp_commands_thru_mock
    
  2. Two new regression tests added (also pass):
    • test_flex_parse_raw_stacks_handles_empty_app_settings_dictionary — feeds a Go-shaped stack with appSettingsDictionary: {} and asserts resolve('go', '1.0') returns a runtime named "go" (this test fails on the current dev branch with KeyError).
    • test_flex_parse_raw_stacks_prefers_functions_worker_runtime_when_present — feeds a dotnet-isolated stack and asserts FWR overrides runtime['name'] (preserves canonical-name semantics).
  3. Verified end-to-end against a live Go Flex Consumption app using the editable install:
    az functionapp deployment source config-zip -g <rg> -n <app> --src <zip>
    # -> "Deployment was successful."
    

History Notes

[App Service] az functionapp deployment source config-zip: Fix KeyError 'FUNCTIONS_WORKER_RUNTIME' for Go function apps on Flex Consumption

…rror 'FUNCTIONS_WORKER_RUNTIME' for Go on Flex Consumption

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 20, 2026 04:29
@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Hi @harshivcodes,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Breaking Change Starting...

Thanks for your contribution!

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented May 20, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in the App Service Function App “Flex Consumption” runtime stack parser where Go stacks may return an empty appSettingsDictionary, causing a KeyError when reading FUNCTIONS_WORKER_RUNTIME. This unblocks az functionapp deployment source config-zip (and other az functionapp flows that use _FlexFunctionAppStackRuntimeHelper) for Go apps on Flex Consumption.

Changes:

  • Make _FlexFunctionAppStackRuntimeHelper._parse_raw_stacks safely read FUNCTIONS_WORKER_RUNTIME via nested .get() with fallback to runtime['name'].
  • Add regression tests covering (1) empty appSettingsDictionary (Go shape) and (2) preferring FUNCTIONS_WORKER_RUNTIME when present (e.g., dotnet-isolated).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/azure-cli/azure/cli/command_modules/appservice/custom.py Prevents KeyError by using .get() to read FUNCTIONS_WORKER_RUNTIME, preserving existing fallback behavior.
src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_functionapp_commands_thru_mock.py Adds mocked regression tests for the empty-dictionary case and for the precedence of FUNCTIONS_WORKER_RUNTIME.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yonzhan yonzhan assigned yanzhudd and unassigned jiasli and zhoxing-ms May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants