Fix regression in assigning BicepValue<T> to properties#53934
Merged
ArcturusZhang merged 6 commits intoAzure:mainfrom Nov 26, 2025
Merged
Fix regression in assigning BicepValue<T> to properties#53934ArcturusZhang merged 6 commits intoAzure:mainfrom
ArcturusZhang merged 6 commits intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a regression where assigning a BicepValue<T> from one resource's property to another resource's collection would incorrectly share the BicepValue instance, causing incorrect reference tracking in generated Bicep expressions.
Key Changes:
- Modified collection operations (Add, Insert, indexer set) to create new
BicepValue<T>instances and useAssign()to copy values instead of sharing instances - Changed
BicepListValueReference.Indexfrom read-only to mutable to support efficient index updates - Reordered precedence in
BicepValue.Compile()to check_selfbefore_source - Added comprehensive test coverage (13 new test methods) to validate the fix
- Updated project references in 27 test projects to ensure proper dependencies
Reviewed Changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| BicepValue.cs | Reordered Compile() to prioritize self-reference over source reference |
| BicepValueReference.cs | Made Index property settable for efficient list index updates |
| BicepListOfT.cs | Modified Add, Insert, indexer, and RemoveAt to create new instances and copy values |
| BicepDictionaryOfT.cs | Modified Add and indexer to create new instances and copy values |
| BicepValueToExpressionTests.cs | Added 13 comprehensive test methods covering property and collection reference scenarios |
| BasicContainerRegistryTests.cs | Removed Ignore attribute and added Name assignment that previously failed |
| CHANGELOG.md | Added bug fix entry with issue reference |
| Multiple .csproj files | Added Azure.Provisioning project references to 27 test projects |
sdk/provisioning/Azure.Provisioning/src/Primitives/BicepValueReference.cs
Show resolved
Hide resolved
m-nash
approved these changes
Nov 24, 2025
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #53862
In general, we are having this issue because when assigning values to ordinary properties and collection items, we are using different approach:
When assigning to ordinary properties, we always copies the value into the current BicepValue.
For instance, when we have a string property, we have this:
in the setter, we call the
Assignmethod which copies whatever we have invalue(which is another BicepValue) into_skuName. In this process, the BicepValue here_skuNamehas its ownSelfto track its reference, and thevaluealso has its ownSelf.In collection case, it is different. When we do this:
We only do this internally:
this will add that BicepValue instance into the list, which might hold a Self of a property, and then we modified its self.
This causes a share of instances between this collection and a property in another instance.
This violates our best practice that we should never share instances. And therefore it is causing the issue.
To fix this, when modifying collections, we must first construct a new
BicepValue<T>instance, and then assign the item value into it, and add our own instance into the list to keep the reference correct, and no longer pollute other properties' self reference.Similar issue may exist if a property is a model - in this case, we use the instance passing in instead of copying everything into the current instance in the property. But we have added related best practice in our readme docs, one should not share instances between different places.