Commit graph

345 commits

Author SHA1 Message Date
Luke Hoban ed769377dc
[sdk/python] Avoid 'referenced before assignment' error (#7135)
We have seen cases where a lot of errors like this are reported:

```
UnboundLocalError: local variable 'resources' referenced before assignment
```

This change prevents this failure mode, which might be a symptom of some
other issue, but currently obscures it in the error path.
2021-11-16 13:57:09 -08:00
Ian Wahbe d3b2dedd1d
[sdk/python] Unmarshal output values in component providers (#8212) 2021-11-15 10:12:12 -08:00
Komal 9a30f36c93
[auto/python] - Fix deserialization of event (#8375)
Fixes the deserialization for the `metadata` property on `ResourcePreEvent`, `ResOutputsEvent` and `ResOpFailedEvent`.
2021-11-08 13:05:04 -08:00
Emiliza Gutierrez d243efae19
Revert "[python/sdk] - Remove python 3.6 support (#8161)" (#8332)
This reverts commit 895ae970ac.
2021-11-02 10:19:01 -07:00
Ian Wahbe e629bc32d5
Expand dependencies when marshaling output values (#8301)
* Expand dependencies when marshaling output values

[sdk/python]

* Update CHANGELOG_PENDING.md

* Use existing code

* Fix lint
2021-11-01 11:10:27 -07:00
Ian Wahbe 83e24765f3
.NET & python SDKs parity for bad pulumi versions (#8297)
* .NET & python SDKs parity for bad pulumi versions

They handle invalid Pulumi CLI version gracefully.

* Make python version property lazy

* Clarify .NET logic

* Add python test for validate_pulumi_version

* Add tests for invalid versions

* Fix python test

* Fix typo

* Fix tests

* Have _validate_pulumi_version handle parsing

* Modify python and .NET to parseAndValidate

* Modify typescript and go to parseAndValidate

* fix name
2021-10-27 20:54:23 -07:00
Komal 895ae970ac
[python/sdk] - Remove python 3.6 support (#8161) 2021-10-27 10:35:46 -07:00
iamjekyun 1bb85ca98c
Only prune the trailing spaces in Python automation result (#8160) 2021-10-11 10:26:22 -07:00
alexander-minchin 43f73f2cc1
Fix typo in Output.apply docstring (#8133) 2021-10-04 18:06:43 -07:00
Pat Gavlin 4eec3b7e1b
[sdk/python] Add a smoke test for output deps (#8113)
Ensure that output property dependencies are deserialized and translated
properly.

Fixes #7444.

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
2021-10-02 09:06:11 -07:00
Justin Van Patten 3027d01f25
Enable output values by default (#8014)
* Enable output values by default

Enable output values by default in the resource monitor and change the polarity of the envvar from `PULUMI_ENABLE_OUTPUT_VALUES` to `PULUMI_DISABLE_OUTPUT_VALUES`.

* Marshal unknown as unknown string when `!KeepOutputValues`

Marshal all unknown output values as `resource.MakeComputed(resource.NewStringProperty(""))` when not keeping output values, which is consistent with what the SDKs do.

Otherwise, when `v.OutputValue().Element` is nil, `resource.MakeComputed(v.OutputValue().Element)` will be marshaled as a null value rather than as an unknown sentinel.

* Add MarshalOptions.DontSkipOutputs and use where needed

Before we expanded the meaning of `resource.Output`, `MarshalProperties` always skipped output values:

```go
if v.IsOutput() {
    logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```

As part of expanding the meaning of `resource.Output`, I'd adjusted `MarshalProperties` to only skip output values when the value was unknown and when not keeping output values:

```go
if v.IsOutput() && !v.OutputValue().Known && !opts.KeepOutputValues {
    logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```

However, this doesn't work the way we want when marshaling properties that include unknown output values to a provider that does not accept outputs. In that case, `opts.KeepOutputValues` will be `false` because we want the marshaler to fall back to returning non-output-values (e.g. unknown sentinel value for unknown output values), but instead of getting the intended fallback values, the unknown output values are skipped (not what we want).

I suspect we may be able to delete the output value skipping in `MarshalProperties` altogether (it's odd that it is skipping `resource.Output` but not `resource.Computed`), but to avoid any unintended side effects of doing that, instead, this commit introduces a new `MarshalOptions.DontSkipOutputs` option that can be set to `true` to opt-in to not skipping output values when marshaling. The check in `MarshalProperties` now looks like this:

```go
if !opts.DontSkipOutputs && v.IsOutput() && !v.OutputValue().Known {
    logging.V(9).Infof("Skipping output property for RPC[%s]: %v", opts.Label, key)
}
```

`opts.DontSkipOutputs` is set to `true` when marshaling properties for calls to a provider's `Construct` and `Call`.

* [sdk/nodejs] Deserialize output values

This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.

* [sdk/python] Deserialize output values

This commit adds support for deserializing output values, which is needed in some cases when serialized inputs are returned as outputs in the SDK.
2021-09-24 08:57:04 -07:00
Justin Van Patten 1e09626bc7
[sdk/{nodejs,python}] Fix errors when testing remote components with mocks (#8053)
v3.13.0 introduces support for serializing outputs in inputs as special output value objects in the Node.js and Python SDKs when serializing inputs for remote components and method calls. This functionality is currently disabled by default in the engine (setting the `PULUMI_ENABLE_OUTPUT_VALUES` envvar to a truthy value enables it).

However, unit testing remote components with mocks results in errors being raised in v3.13.0, related to the new output value support. This is due to the mock monitor implementation saying it supports all features (which now includes output values), so the SDK serializers are serializing outputs as output values, which the mock monitor can't handle correctly.

This change addresses the issue by updating the mock monitor implementation in the Node.js and Python SDKs to indicate the specific features that are supported, excluding support for output values. New tests with mocks fail before the change and pass after.
2021-09-24 06:08:13 -07:00
Komal 212ac89366
[auto/python] - Fix a bug in printing stack. (#8032) 2021-09-22 16:49:03 -07:00
Justin Van Patten df50c4492e
[sdk/python] Fix serializing output values within dicts (#7996)
Pass along the `keep_output_values` param when serializing values within dicts.
2021-09-17 20:53:29 -07:00
Komal 452e3f76f1
Fix python lint issues (#7988) 2021-09-16 17:42:35 -07:00
Justin Van Patten 4f3f366695
[sdk/python] Marshal output values (#7926)
This change adds support for marshaling outputs as output values in the Python SDK.
2021-09-15 21:49:23 -07:00
Justin Van Patten ed4b53d3ae
Add monitor feature for output values (#7870) 2021-09-15 14:16:00 -07:00
Anton Tayanovskyy 151fdff906
Lower the BrokenDynamicProvider regression test from integration to mock (#7951) 2021-09-10 17:25:48 -04:00
Anton Tayanovskyy d7b9c01999
Fix 7862 (#7887)
* Fix 7862

* Add a unit test that reproduces the timeout

* Add a CHANGELOG entry
2021-09-07 11:30:39 -04:00
Luke Hoban f89e9a29f5
Revert "Allow Python dynamic provider resources to be constructed outside of __main__ (#7755)" (#7889)
This reverts commit ebb0e6aaed.

The changes in #7755 introduced a regression tracked in #7795.  It is not yet clear how to retain the desired behaviour introduced in #7755 while avoiding this regression, so for now we will revert those changes, and re-open #7453 to track a deeper fix.  That fix may require making changes to upstream `dill` to properly support these serialization requirements.

Fixes #7795.
2021-09-01 20:49:04 -07:00
Anton Tayanovskyy 1b67c9ee52
Satisfy Python lint: factor out URN parsing in Python and other fixes (#7821)
* Factor out URN parsing in Python

* More code sharing to satisfy lint dup code detector

* Fix lint R1735 recommendation of empty dict literal

* Fix lint issue insisting on known encoding during open()

* Fix parsing URNs without urn_name; test; exception wrapper
2021-08-24 09:57:51 -04:00
Jan Češpivo e67334db1d
Added support for custom naming of dynamic provider resource (#7633)
Now there is not possible to change a name of dynamic provider resource without copying a code of the `pulumi.sdk.python.lib.pulumi.dynamic.dynamic.Resource` and changing the hard-coded name `"pulumi-python:dynamic:Resource"`. I successfully uses this proposal to make it possible.

Usage:
```python
class CustomResource(
    Resource, name="my-custom-provider:CustomResource"
):
   ...
```

Co-authored-by: Pat Gavlin <pgavlin@gmail.com>
2021-08-17 14:15:53 -07:00
Anton Tayanovskyy 4d4642c23d
Remove threading from mock tests to fix AIO waits on diff event loop (#7666)
* Remove threading from mock tests to fix AIO waits on diff event loop

* Add reference to the proper fix
2021-08-16 18:53:15 -04:00
Anton Tayanovskyy cd885bded5
Re-introduce the fix for 7734 and mitigate CI hangs (#7746)
* Revert the revert

* Fix exception bleed from one test suite to another

* Fix typos
2021-08-13 11:07:13 -04:00
Luke Hoban ebb0e6aaed
Allow Python dynamic provider resources to be constructed outside of __main__ (#7755)
The underlying library `dill` that we use for serializing dynamic providers into Pulumi state for Python dynamic providers serializes classes differently depending on whether they are in `__main__` or in another module.  We need the by-value serialization to be applied in all cases.

https://github.com/uqfoundation/dill/issues/424 is tracking adding the ability into `dill` to specify this by-value serialization explicitly, but until then, we will temporarily re-write the `__module__` of a provder class prior to serialization, so that `dill` behaves as we need for the dynamic provider use case.

Fixes #7453.
2021-08-12 20:02:17 -07:00
Pat Gavlin ecb98b66fd
[sdk/python] Transitive component dependencies. (#7732)
Implement Node/.NET-style dependency semantics for component resources.
Depending on a component implicitly depends on all of the component's
children. The exact set of children depends on exactly when the
component resource is observed.

Part of #7542.
2021-08-11 21:52:16 -05:00
Anton Tayanovskyy ea333681ab
Revert "Fix hangs in core SDK when monitor unavailable (#7734)" (#7744)
This reverts commit e567b4762f.
2021-08-11 17:13:37 -04:00
Justin Van Patten 0b782ea884
[sdk/python] Fix pulumi.property's default value handling (#7736)
We were incorrectly setting the name of the attribute rather than the intended default value.
2021-08-11 09:15:46 -07:00
Anton Tayanovskyy e567b4762f
Fix hangs in core SDK when monitor unavailable (#7734)
* Fix hangs in core SDK when monitor unavailable

* merged
2021-08-11 10:50:27 -04:00
Nikhil Benesch 442cdf5743
python: Use Sequence rather than List in Resource fields (#7700)
Similar to #5282, but for core SDK types. The tl;dr is that because
Sequence[T] is covariant, constructing resources becomes much more
ergonomic.

Fix #7693.
2021-08-03 14:03:42 -07:00
Anton Tayanovskyy 13b6cc5eea
Fix reflecting list type annotations (#7681)
* Fix reflecting list type annotations

* Fix typo and add a test case

* Typo
2021-07-30 09:35:16 -04:00
Justin Van Patten 74ab9e0869
[sdk/python] Handle unknown results from methods (#7677)
This fixes handling of unknown results from methods in the Python SDK. Node.js and Go were already handling this appropriately.
2021-07-29 11:11:52 -07:00
Anton Tayanovskyy bc96ac799d
Inputty depends_on support for Python (#7559)
* Inputty depends_on support for Python

* Fix circular import

* Add a test, fix bugs found by test

* Fix typo

* Minimize loss of dep information in presence of unks to match Node behavior

* Add CHANGELOG entr

* Update sdk/python/lib/pulumi/output.py

Co-authored-by: Justin Van Patten <jvp@justinvp.com>

* Update sdk/python/lib/test/test_resource.py

Co-authored-by: Justin Van Patten <jvp@justinvp.com>

* Fix _is_prompt

* Enhance tests, found out a gap against Node impl

* Add non-listy case

* Internal functional combinators

* Do not use all/deep await when merging

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
2021-07-28 09:49:07 -04:00
Justin Van Patten a05c3a4e9b
Set the package on DependencyProviderResource (#7630)
When initializing `DependencyProviderResource`, pass the package to the base constructor instead of an empty string s.t. the provider is usable when its package is read.
2021-07-27 06:50:24 -07:00
Justin Van Patten e8bd8e5e1f
Rehydrate provider resources in Construct (#7624)
Previously, any provider resource passed to multi-lang components would be instantiated as a `DependencyProviderResource` inside `Construct`, which prevents the component from being able to easily access the provider's state as an instance of of the provider (e.g. `*aws.Provider`).

This change attempts to rehydrate the provider resource in the same way that resource references are rehydrated, if it's been registered, s.t. the specific provider resource type is instantiated with its state. Otherwise falling back to returning `DependencyProviderResource`.
2021-07-23 14:10:06 -07:00
Justin Van Patten 68458bfab3
[sdk/python] Support for implementing methods in provider (#7555) 2021-07-19 14:58:55 -07:00
Nikhil Benesch c782a298a1
Make Output[T] covariant in Python SDK (#7483)
In short, this allows subtyping to correctly "propagate" through an Output;
if Cow is a subtype of Animal, this commit makes it so Output[Cow] is
treated as a subtype of Output[Animal].

Without this change, users of the Python SDK occasionally contend with a
confusing error message that is resolved by adding a call to
`.apply(lambda x: x)` to satisfy mypy.

Touches #3767.
Fix #6843.
2021-07-16 12:30:04 -07:00
Anton Tayanovskyy 36d11261c6
Quick fix for provider flag ordering (#7412)
* specify plugin arguments before other flags

* Ignore these pesky flags in python provider.main

Co-authored-by: evanboyle <evan@pulumi.com>
2021-07-07 11:07:04 -04:00
Pat Gavlin 713b901b0c
[sdk/python] Translate property dep keys. (#7443)
The map of property dependencies the Python SDK receives from the
engine uses `camelCase` property keys, but the SDK performs lookups
using `snake_case` property keys. Fix this by translating the map's keys
from `camelCase` to `snake_case` prior to performing any lookups.
2021-07-07 20:01:41 +10:00
Luke Hoban eb32039013
Add replaceOnChanges resource option (#7226)
Adds a new resource option to force replacement when certain properties report changes, even if the resource provider itself does not require a replacement.

Fixes #6753.

Co-authored-by: Levi Blackstone <levi@pulumi.com>
2021-07-01 13:32:08 -06:00
Justin Van Patten 84b574f0df
Initial support for resource methods (authoring from Node.js, calling from Python) (#7363)
Adds initial support for resource methods (via a new `Call` gRPC method similar to `Invoke`), with support for authoring methods from Node.js, and calling methods from Python.
2021-06-30 07:48:56 -07:00
Justin Van Patten e966c65f69
Fix pylint issues (#7389) 2021-06-29 21:35:25 -07:00
Evan Boyle 634e97cd55
Include config secret info in Construct calls (#7358) 2021-06-24 15:38:01 -07:00
Anton Tayanovskyy b16d50085b
Fix hanging deployments and improve errmsgs for programs with incorrect typings for output values (#7049)
* Do not hang but propagate exception when it happens in resolve_outputs

* Add an integration test for the issue

* Better error message

* Add CHANGELOG_PENDING entry

* Update sdk/python/lib/pulumi/runtime/rpc.py

Co-authored-by: Justin Van Patten <jvp@justinvp.com>

* Address PR feedback and tighten path param typing

* Given Windows builder is failing, allow 2x time for the test

* Give some more time to the Windows runner

* Attempt to solve differently

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
2021-06-23 11:27:17 -04:00
Justin Van Patten 48bbc28d9e
[sdk/go] Specify known when creating outputs for construct (#7343)
If an input is an unknown value or contains unknowns, specify `false` for `known` when creating the output.
2021-06-21 09:51:41 -07:00
Luke Hoban 965d23ba2a
[sdk/python] Ensure Output objects are not iterable (#7288)
Although `Output` objects can never correct support iteration, Python will see the implementation of `__getitem__` and try to iterate the object, leading to an infinite loop.  To prevent this, we need to explicitly implement `__iter__` and make it return a `TypeError` to prevent iteration (and offer a useful error message).

Fixes #5028.
2021-06-15 09:25:24 +10:00
Justin Van Patten 63e129a386
[sdk/python] Reduce log.debug calls for improved performance (#7295)
`log.debug` messages are part of an update and get sent to the service. Reducing the number of `log.debug` calls can significantly improve the performance of a program. This commit changes the debug logging in the Python SDK to be similar to the debug logging in the Node.js SDK.

 - An `excessive_debug_output` variable has been added (that can be set to `True` during debugging), but otherwise will avoid a large number of `log.debug` calls.
- Some unhelpful/redundant `log.debug` calls have been deleted.
2021-06-14 10:24:01 -07:00
Luke Hoban 26e252f241
Ensure Output.from_input({}) returns {} instead of [] (#7254)
Fixes #7252.
2021-06-09 19:48:10 +10:00
Luke Hoban bd6410e2fb
[sdk/python] Avoid exponential complexity for from_input/all (#7175)
These mutually recursive functions unintentionally had exponential complexity in nesting depth of objects, arg types and most likely arrays.

Remove the exponential complexity by avoiding direct recursion of from_input on itself, and relying on mutual recursion with all alone to reduce nested substructure.

Also simplify the implementation to aid readability.

Fixes pulumi/pulumi-kubernetes#1597.
Fixes pulumi/pulumi-kubernetes#1425.
Fixes pulumi/pulumi-kubernetes#1372.
Fixes #3987.
2021-06-01 13:11:22 +10:00
Justin Van Patten d6b7762102
Temporarily disable config secrets warning (#7129)
Temporarily disable the new config secret warning to avoid unactionable warnings from provider `config` modules. We'll re-enable the warning when we've addressed that issue.
2021-05-24 16:06:27 -07:00