FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Restore ReadOnly after failed Set-Variable option updates by dkontyko · Pull Request #27877 · PowerShell/PowerShell · GitHub

Restore ReadOnly after failed Set-Variable option updates - #27877

Open
David Kontyko (dkontyko) wants to merge 8 commits into
PowerShell:masterfrom
dkontyko:copilot/update-set-variable-fix
Open

Restore ReadOnly after failed Set-Variable option updates#27877
David Kontyko (dkontyko) wants to merge 8 commits into
PowerShell:masterfrom
dkontyko:copilot/update-set-variable-fix

Conversation

Copy link
Copy Markdown
Contributor

PR Summary

Restore the ReadOnly option when Set-Variable -Force temporarily removes it and a subsequent option update fails.

Add regression coverage for ReadOnly, ReadOnly | Private, and ReadOnly | AllScope, plus compatibility tests documenting the intentionally retained behavior for cases 1 and 2 of #27679.

PR Context

When Set-Variable -Force operates on a ReadOnly variable, it temporarily removes ReadOnly before applying the requested changes. If applying -Option Constant fails with VariableCannotBeMadeConstant, the temporary removal was not reverted, leaving the variable writable.

This change restores ReadOnly in the existing handled exception paths while preserving other current option flags. It addresses case 3 of #27679, as agreed by the PowerShell cmdlets working group.

For backward compatibility, cases 1 and 2 continue to retain value and description changes made before the option update fails. Tests document this behavior explicitly.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s):
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed:
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Added regression and compatibility tests

Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 21, 2026 02:03
David Kontyko (dkontyko) requested a review from a team as a code owner August 21, 2026 02:03

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

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

This pull request fixes a Set-Variable -Force edge case where ReadOnly was temporarily removed to perform an update, but not restored when a subsequent option update (notably -Option Constant) failed. It also adds regression/compatibility tests to lock in the intended behavior for issue #27679 cases 1–3.

Changes:

  • Restore the ReadOnly flag in the existing handled failure paths when Set-Variable -Force temporarily cleared it and the option update fails.
  • Add Pester coverage for restoring ReadOnly across ReadOnly, ReadOnly | Private, and ReadOnly | AllScope, and document the intentionally retained mutation behavior for issue #27679 cases 1 and 2.
Show a summary per file
File Description
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs Tracks whether ReadOnly was temporarily cleared and restores it in the handled exception paths when option updates fail.
test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 Adds regression/compatibility tests covering the issue #27679 scenarios and option combinations.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

David Kontyko and others added 2 commits August 24, 2026 11:03
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 15243fcb-972e-4518-b3b2-e0c5021b4199
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3068dc60-7ac0-4d2b-bcc3-020ac4816d67
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL