pulumi/sdk/python/lib
Justin Van Patten 0b1414dc6d
[sdk/python] Fix mocks issue when passing a resource more than once (#6479)
This change avoids `RuntimeError: There is no current event loop in thread '<thread_name>'` errors when passing a resource as an input multiple times when using mocks.

The problem is that when using mocks, we deserialize the gRPC inputs before passing them to the user's mock methods. Deserializing inputs doesn't typically require an event loop, however, during deserialization of resource references, we end up creating some instances of `Future`, which does require an event loop to be present for the current thread. If this is done multiple times for a resource, it's possible that `deserialize_properties` will be called on an asyncio thread that doesn't yet have an event loop, resulting in the error being raised.

The error does not occur when only passing the resource reference once because typically the thread (e.g. `asyncio_0`) used in that case will have already had an event loop created for it due to the use of the internal `_syncawait` when _serializing_ the source resource's properties, which ensures an event loop is set for the thread.

The fix is to ensure an event loop is created for the thread in the mocks implementation before calling `deserialize_properties`.
2021-03-09 13:48:24 -08:00
..
pulumi [sdk/python] Fix mocks issue when passing a resource more than once (#6479) 2021-03-09 13:48:24 -08:00
test Upgrading Go to 1.16.x (#6470) 2021-03-09 20:05:23 +00:00
test_with_mocks [sdk/python] Fix mocks issue when passing a resource more than once (#6479) 2021-03-09 13:48:24 -08:00
setup.py [Automation API] Python Implementation (#5979) 2021-01-12 16:55:59 -08:00