From fc38d7d4d9bfc7d58613e620de15635e40c4201a Mon Sep 17 00:00:00 2001 From: Luke Hoban Date: Tue, 16 Jul 2019 11:15:26 -0700 Subject: [PATCH] Handle mixed versions of Resources in parent hierarchy (#2942) For new properties added to `Resource`, we need to make sure to handle cases where these are undefined as they may not be available on versions of `Resource` that come from older SDK versions, which could me side-by-side in a single Pulumi program execution. Fixes #2938 --- CHANGELOG.md | 6 +++++- sdk/nodejs/resource.ts | 18 ++++++++++++++---- sdk/nodejs/runtime/resource.ts | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fa2a0ff3..9383fc009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ CHANGELOG [#2672](https://github.com/pulumi/pulumi/issues/2672)) - Fix an issue where a file archive created on Windows would contain back-slashes - [#2784](https://github.com/pulumi/pulumi/issues/2784)) + [#2784](https://github.com/pulumi/pulumi/issues/2784) - Fix an issue where output values of a resource would not be present when they contained secret values, when using Python. @@ -24,6 +24,10 @@ CHANGELOG - Add the ability to pass a customTimeouts object from the providers across the engine to resource management. (fixes [#2665](https://github.com/pulumi/pulumi/issues/2665)) +- Fix a crash when two different versions of `@pulumi/pulumi` are used in the same Pulumi program + [#2942](https://github.com/pulumi/pulumi/issues/2942) + + ## 0.17.22 (2019-07-11) - Improve update performance in cases where a large number of log messages are diff --git a/sdk/nodejs/resource.ts b/sdk/nodejs/resource.ts index 010a63478..0a88f302b 100644 --- a/sdk/nodejs/resource.ts +++ b/sdk/nodejs/resource.ts @@ -143,16 +143,24 @@ export abstract class Resource { /** * @internal * A list of aliases applied to this resource. + * + * Note: This is marked optional only because older versions of this library may not have had + * this property, and marking optional forces conumers of the property to defensively handle + * cases where they are passed "old" resources. */ // tslint:disable-next-line:variable-name - readonly __aliases: Input[]; + readonly __aliases?: Input[]; /** * @internal * The name assigned to the resource at construction. + * + * Note: This is marked optional only because older versions of this library may not have had + * this property, and marking optional forces conumers of the property to defensively handle + * cases where they are passed "old" resources. */ // tslint:disable-next-line:variable-name - private readonly __name: string; + private readonly __name?: string; /** * @internal @@ -222,8 +230,10 @@ export abstract class Resource { // Make a copy of the aliases array, and add to it any implicit aliases inherited from its parent opts.aliases = [...(opts.aliases || [])]; - for (const parentAlias of opts.parent.__aliases) { - opts.aliases.push(inheritedChildAlias(name, opts.parent.__name, parentAlias, t)); + if (opts.parent.__name) { + for (const parentAlias of (opts.parent.__aliases || [])) { + opts.aliases.push(inheritedChildAlias(name, opts.parent.__name, parentAlias, t)); + } } this.__providers = opts.parent.__providers; diff --git a/sdk/nodejs/runtime/resource.ts b/sdk/nodejs/runtime/resource.ts index eff43e8c0..8200f6b2a 100644 --- a/sdk/nodejs/runtime/resource.ts +++ b/sdk/nodejs/runtime/resource.ts @@ -346,7 +346,7 @@ async function prepareResource(label: string, res: Resource, custom: boolean, // simplifying aliases down to URNs. const aliases = []; const uniqueAliases = new Set(); - for (const alias of res.__aliases) { + for (const alias of (res.__aliases || [])) { const aliasVal = await output(alias).promise(); if (!uniqueAliases.has(aliasVal)) { uniqueAliases.add(aliasVal); @@ -564,6 +564,7 @@ export function listResourceOutputs( typeFilter = isAny; } + return query .from( invoke("pulumi:pulumi:readStackResourceOutputs", {