Skip to content

[Core] Preserve identities when single instance is removed - #34383

Merged
Naga Nandyala (naga-nandyala) merged 1 commit into
Azure:devfrom
nateprewitt:identities_removal_fix
Nov 9, 2026
Merged

Naga Nandyala (naga-nandyala) merged 1 commit into
Azure:devfrom
nateprewitt:identities_removal_fix

Conversation

@nateprewitt

@nateprewitt Nate Prewitt (nateprewitt) commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ️✔️ All clear

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

Related command
N/A

Description
This was an issue found working on #34305. There is an assumption built into identity removal that selected identity removal will always be for more than one instance. If exactly one instance is removed from a set, the entire identities collection is dropped by the else statement. This change instead checks for truthiness in the list (we could also check for len but this would typically be considered more pythonic).

There's no context on why the >1 check was originally added in the originating PR, but it seems like it was a confusion of user_assigned and identities. i.e. if there is more than one identity if len(identities) > 1 then try to remove. That has other issues though where it assumes a removal with only one identity constitutes identities = {} which is also wrong.

Testing Guide

From the repository root in a configured CLI development environment:

python -m pytest -q src\azure-cli-core\azure\cli\core\tests\test_aaz_identity.py

New tests verify that removing one specified user-assigned identity preserves unselected identities, and requesting removal of an unassigned identity leaves existing identities unchanged. Both cases cover resources with and without a system-assigned identity.

History Notes

[Core] Fix removal of a single specified user-assigned identity incorrectly removing all user-assigned identities.


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

Copilot AI balanced review requested due to automatic review settings November 9, 2026 18:31
@azure-pipelines

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

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

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

@x-engineering-agent

Copy link
Copy Markdown
Contributor

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

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 are reported for the selective identity-removal fix.

No open issues 🎉

What changed in this PR

Fixes shared AAZ identity-removal logic so removing one specified user-assigned identity preserves unselected identities. The issue was discovered during Storage management API work.

Changes:

  • Uses a nonempty-list check to distinguish selective removal from removing all user-assigned identities.
  • Adds regression tests for removing one assigned or unassigned identity, both with and without a system-assigned identity.
File Description
src/​azure-cli-core/​azure/​cli/​core/​tests/​test_aaz_identity.py Adds identity-preservation regression tests.
src/​azure-cli-core/​azure/​cli/​core/​aaz/​_field_value.py Corrects selective removal for a single identity.

Review effort: Balanced

@nateprewitt

Copy link
Copy Markdown
Member Author

mansoor sarfraz (@msarfraz) Aditya Pujara (@a0x1ab), can we get eyes on this for current milestone since it's not a new PR?

@naga-nandyala
Naga Nandyala (naga-nandyala) merged commit 1f3236e into Azure:dev Nov 9, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants