Filter out internal properties when deserializing data (#3560)

This commit is contained in:
CyrusNajmabadi 2019-11-21 17:05:39 -05:00 committed by GitHub
parent eedd277cd7
commit d7e93472b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,35 @@
// Copyright 2016-2019, Pulumi Corporation
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Pulumi.Serialization;
using Xunit;
namespace Pulumi.Tests.Serialization
{
public class InternalPropertyTests : ConverterTests
{
[Fact]
public void IgnoreInternalProperty()
{
var data = Converter.ConvertValue<ImmutableDictionary<string, string>>("", new Value
{
StructValue = new Struct
{
Fields =
{
{ "a", new Value { StringValue = "b" } },
{ "__defaults", new Value { BoolValue = true } },
}
}
});
Assert.True(data.IsKnown);
Assert.True(data.Value.ContainsKey("a"));
Assert.Equal("b", data.Value["a"]);
Assert.False(data.Value.ContainsKey("__defaults"));
}
}
}

View file

@ -75,6 +75,13 @@ namespace Pulumi.Serialization
foreach (var (key, element) in v.StructValue.Fields)
{
// Unilaterally skip properties considered internal by the Pulumi engine.
// These don't actually contribute to the exposed shape of the object, do
// not need to be passed back to the engine, and often will not match the
// expected type we are deserializing into.
if (key.StartsWith("__"))
continue;
var elementData = Deserialize(element);
(isKnown, isSecret) = OutputData.Combine(elementData, isKnown, isSecret);
result.Add(key, elementData.Value);