Python: Ignore internal properties when unmarshaling (#5251)

This commit is contained in:
Justin Van Patten 2020-08-29 01:26:16 +00:00 committed by GitHub
parent 493136d2f0
commit 69fbd70330
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View file

@ -2,7 +2,10 @@ CHANGELOG
=========
## HEAD (Unreleased)
_(none)_
- Python SDK: Avoid raising an error when internal properties don't match the
expected type.
[#5251](https://github.com/pulumi/pulumi/pull/5251)
## 2.9.1 (2020-08-127

View file

@ -255,6 +255,14 @@ def deserialize_properties(props_struct: struct_pb2.Struct, keep_unknowns: Optio
# since we can only set secret outputs on top level properties.
output = {}
for k, v in list(props_struct.items()):
# 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.
# Keep "__provider" as it's the property name used by Python dynamic providers.
if k.startswith("__") and k != "__provider":
continue
value = deserialize_property(v, keep_unknowns)
# We treat values that deserialize to "None" as if they don't exist.
if value is not None:

View file

@ -913,6 +913,20 @@ class DeserializationTests(unittest.TestCase):
self.assertEqual(val["listWithMap"]["value"][0]["regular"], "a normal value")
self.assertEqual(val["listWithMap"]["value"][0]["secret"], "a secret value")
def test_internal_property(self):
all_props = struct_pb2.Struct()
all_props["a"] = "b"
all_props["__defaults"] = []
all_props["c"] = {"foo": "bar", "__defaults": []}
all_props["__provider"] = "serialized_dynamic_provider"
all_props["__other"] = "baz"
val = rpc.deserialize_properties(all_props)
self.assertEqual({
"a": "b",
"c": {"foo": "bar"},
"__provider": "serialized_dynamic_provider",
}, val)
@input_type
class FooArgs: