Skip to content

[Lab] Fix #31857: az lab vm create: Fix KeyError when the formula omits optional properties - #34473

Open
chessMan (mohitmishra786) wants to merge 1 commit into
Azure:devfrom
mohitmishra786:31857-lab-formula-keyerror
Open

chessMan (mohitmishra786) wants to merge 1 commit into
Azure:devfrom
mohitmishra786:31857-lab-formula-keyerror

Conversation

@mohitmishra786

@mohitmishra786 chessMan (mohitmishra786) commented Nov 20, 2026 •

Copy link
Copy Markdown

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ️✔️ None

Related command

az lab vm create --formula

Description

Fixes #31857.

The formula returned by the service leaves out properties that are not set. _validate_other_parameters read them with plain indexing, so a formula without tags failed with KeyError: 'tags', and with --tags it failed on the next missing property, artifacts.

This uses .get() for those lookups, so a missing value leaves the argument unset, the same as when the user does not pass it. The same change is applied to osType, disallowPublicIpAddress and isAuthenticationWithSshKey, which are read the same way later in the same command.

Testing Guide

Added unit tests in test_lab_validators.py:

  • a formula without tags, artifacts, notes, allowClaim or storageType, with and without --tags;
  • a formula with all of these set, to check they are still copied;
  • a formula without isAuthenticationWithSshKey.

The first and third fail on dev with KeyError: 'tags' and KeyError: 'isAuthenticationWithSshKey' and pass with this change. All lab tests pass locally (12 passed, 1 skipped; the skip is the same on dev).


This checklist is used to make sure that common guidelines for a pull request are followed.

…rmula omits optional properties

The formula returned by the service leaves out properties that are not
set, such as tags and artifacts, but the validators read them with plain
indexing. Use .get() for these lookups so missing values are left unset.
Copilot AI balanced review requested due to automatic review settings November 20, 2026 08:19
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Nov 20, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution chessMan (@mohitmishra786)! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change intended to prevent errors from missing optional formula properties.

No open issues 🎉

What changed in this PR

Fixes #31857 by preventing KeyError in az lab vm create --formula when service responses omit optional formula properties.

Changes:

  • Uses .get() for optional formula fields, including VM settings, network configuration, and authentication selection.
  • Adds regression tests for omitted properties, explicit tags, and copying populated formula values.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​lab/​validators.py Safely reads optional formula properties.
src/​azure-cli/​azure/​cli/​command_modules/​lab/​tests/​latest/​test_lab_validators.py Tests missing properties and preservation of supplied formula values.

Review effort: Balanced

@mohitmishra786

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Amadeus"

@mohitmishra786

chessMan (mohitmishra786) commented Nov 20, 2026 •

Copy link
Copy Markdown
Author

mansoor sarfraz (@msarfraz) Could you take a look when you have time? It is a small fix in the same formula handling as #34354, which you reviewed. Thanks.

@x-engineering-agent

Copy link
Copy Markdown
Contributor

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

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating Azure Dev Test Lab VM with az lab create and a formula errors

5 participants