Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk/nodejs] Fix provider for resource methods #13796

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

justinvp
Copy link
Member

The Resource class in the Node.js SDK has the following internal property:

/** @internal */
readonly __prov?: ProviderResource;

When a resource is created, the provider specified for the resource is stored in this property. If it is set, it is passed along in the Call request when a method is called on the resource.

Prior to #13282, the property was only set for custom resources in Resource's constructor:

this.__prov = custom ? opts.provider : undefined;

With #13282, it was changed to also store the value for remote components:

- this.__prov = custom ? opts.provider : undefined;
+ this.__prov = custom || remote ? opts.provider : undefined;

This regressed the behavior when calling a method on a remote component that had an explicit provider that wasn't the component provider, but some other provider (e.g. AWS provider) specified as:

const component = new MyRemoteComponent("comp", {
}, { provider: awsProvider });

The awsProvider was being stored in Resource.__prov, and when making the method call on the resource, it would try to invoke Call on the AWS provider, rather than calling the remote component provider's Call, which resulted in an error.

Note that specifying the AWS provider using the more verbose providers: [awsProvider] works around the issue.

The fix is to only set __prov if the provider's package is the same as the resource's package. Otherwise, don't set it, because the user is specifying a provider with the provider: awsProvider syntax as shorthand for providers: [awsProvider].

Fixes #13777

@justinvp justinvp requested a review from a team August 26, 2023 00:46
@pulumi-bot
Copy link
Contributor

pulumi-bot commented Aug 26, 2023

Changelog

[uncommitted] (2023-08-30)

Bug Fixes

  • [sdk/nodejs] Fix provider used for resource methods
    #13796

sdk/nodejs/resource.ts Outdated Show resolved Hide resolved
The `Resource` class in the Node.js SDK has the following internal
property:

```typescript
/** @internal */
readonly __prov?: ProviderResource;
```

When a resource is created, the provider specified for the resource is
stored in this property. If it is set, it is passed along in the `Call`
request when a method is called on the resource.

Prior to #13282, the property was only set for custom resources in
`Resource`'s constructor:

```typescript
this.__prov = custom ? opts.provider : undefined;
```

With #13282, it was changed to also store the value for remote
components:

```diff
- this.__prov = custom ? opts.provider : undefined;
+ this.__prov = custom || remote ? opts.provider : undefined;
```

This regressed the behavior when calling a method on a remote component
that had an explicit provider that wasn't the component provider,
but some other provider (e.g. AWS provider) specified as:

```typescript
const component = new MyRemoteComponent("comp", {
}, { provider: awsProvider });
```

The `awsProvider` was being stored in `Resource.__prov`, and when making
the method call on the resource, it would try to invoke `Call` on the
AWS provider, rather than calling the remote component provider's
`Call`, which resulted in an error.

Note that specifying the AWS provider using the more verbose
`providers: [awsProvider]` works around the issue.

The fix is to only set `__prov` if the provider's package is the same as
the resource's package. Otherwise, don't set it, because the user is
specifying a provider with the `provider: awsProvider` syntax as
shorthand for `providers: [awsProvider]`.
Copy link
Contributor

@dixler dixler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@justinvp justinvp added this pull request to the merge queue Aug 30, 2023
Merged via the queue into master with commit 0650e8b Aug 30, 2023
44 checks passed
@justinvp justinvp deleted the justin/methods_provider branch August 30, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected error "Call is not yet implemented"
3 participants