-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix regression in assigning BicepValue<T> to properties #53934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix regression in assigning BicepValue<T> to properties #53934
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
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.