-
Notifications
You must be signed in to change notification settings - Fork 44
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 transform property value to preserve nil arrays and objects #2655
Conversation
This change is part of the following stack: Change managed by git-spice. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2655 +/- ##
=======================================
Coverage 69.97% 69.98%
=======================================
Files 367 367
Lines 44504 44512 +8
=======================================
+ Hits 31142 31150 +8
Misses 11735 11735
Partials 1627 1627 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
This is wild. What is |
func TestIsNilArray(t *testing.T) { | ||
t.Parallel() | ||
|
||
require.True(t, isNilArray(resource.PropertyValue{V: []resource.PropertyValue(nil)})) |
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.
I am wondering now, why are these things valid values in Pulumi?
Could we assert against their existence or normalize them to a normal semantic form?
That is, I understand that in TF type array may have a distinct nil
value, but it is surprising to me that in either Pulumi or TF space we would want to make a distinction between nil
and a special nil array
. I would expect that at this layer we want to have only one nil
.
So whichever code constructed this value to represent a nil:
resource.PropertyValue{V: []resource.PropertyValue(nil)}
Should have constructed this value instead which canonically represents nil
:
resource.PropertyValue{}
?
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.
Yeah, we shouldn't be making these in the first place. I've opened #2662 to follow up here.
However, I still think that Transform shouldn't be changing values as well, so I think this PR is still valid. Here it changes a nil
to empty
which are semantically different.
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.
Yeah I'm ok with the follow up.
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.
Do we have evidence of this happening in the wild?
I'm pretty sure we have rapid
generators for resource.PropertyValue
. Can we write a test that asserts TransformPropertyValue(path, identity, value) == (value, nil)
?
Yeah we do get nil arrays out of I am not convinced that this is a supported value for I'll open a follow-up to chase down what is constructing this value but it might have other effects, so might not be trivial to change. Opened #2662 |
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.
Accepting as workaround but probably need to tidy this up with contract.Assertf once the root cause is fixed.
This PR has been shipped in release v3.97.0. |
The
propertyvalue.Transform
functions had a bug where it would always mutate nil arrays and maps into empty ones:would become:
This had to do with typed nil interfaces in go: https://dave.cheney.net/2017/08/09/typed-nils-in-go-2
The
V
inresource.PropertyValue
is an interface, so it might be non-nil!= nil
but the underlying value is nil.This change adds a fix and some tests for the problem.