iwahbe/8474/dont serialize unknown values (#8475)

* Don't serialize unknown values

* Add test

* Update CHANGELOG_PENDING.md
This commit is contained in:
Ian Wahbe 2021-11-22 12:40:17 -08:00 committed by GitHub
parent d9dd88c740
commit 4029a1c89b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -29,3 +29,6 @@
- [cli] - Catch expected errors in stacks with filestate backends.
[#8455](https://github.com/pulumi/pulumi/pull/8455)
- [sdk/dotnet] - Do not attempt to serialize unknown values.
[#8475](https://github.com/pulumi/pulumi/pull/8475)

View file

@ -116,8 +116,27 @@ namespace Pulumi.Tests.Serialization
ImmutableDictionary<string, object>.Empty.Add("foo",
ImmutableDictionary<string, object>.Empty.Add("foo", "hello"))
},
// Repro #8474
UnknownDefaultValue<ImmutableArray<bool>>(),
UnknownDefaultValue<ImmutableArray<object>>(),
UnknownDefaultValue<ImmutableDictionary<string,bool>>(),
};
// Ensure that we can safely serialize unknown values. This causes issues with values whose
// defaults are not safe to interact with (ImmutableArray<T> for example).
private static object[] UnknownDefaultValue<T>()
where T : notnull
{
T inner = default;
var outputdata = OutputData.Create(ImmutableHashSet<Resource>.Empty, inner!, isKnown: false, isSecret: false);
var output = new Output<T>(Task.FromResult(outputdata));
return new object[]
{
output,
ImmutableDictionary<string, object>.Empty.Add(Constants.SpecialSigKey, Constants.SpecialOutputValueSig),
};
}
[Theory]
[MemberData(nameof(SerializeData))]
public static Task TestSerialize(object input, object expected) => RunInNormal(async () =>

View file

@ -150,7 +150,13 @@ $"Tasks are not allowed inside ResourceArgs. Please wrap your Task in an Output:
var isSecret = data.IsSecret;
var valueSerializer = new Serializer(_excessiveDebugOutput);
var value = await valueSerializer.SerializeAsync($"{ctx}.id", data.Value, keepResources, keepOutputValues: false).ConfigureAwait(false);
// It is unsafe to serialize unknown values.
object? value = isKnown
? await valueSerializer.SerializeAsync(
$"{ctx}.id", data.Value, keepResources, keepOutputValues: false).ConfigureAwait(false)
: null;
var promiseDeps = valueSerializer.DependentResources;
DependentResources.UnionWith(promiseDeps);
propResources.UnionWith(promiseDeps);