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.
This commit is contained in:
parent
233b396f29
commit
f89e9a29f5
|
@ -17,5 +17,8 @@
|
|||
[#7865](https://github.com/pulumi/pulumi/pull/7865)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- [sdk/python] Fix a regression in Python dynamic providers introduced in #7755.
|
||||
|
||||
- [automation/go] Fix loading of stack settings/configs from yaml files.
|
||||
[#pulumi-kubernetes-operator/183](https://github.com/pulumi/pulumi-kubernetes-operator/issues/183)
|
||||
|
|
|
@ -222,18 +222,10 @@ def serialize_provider(provider: ResourceProvider) -> str:
|
|||
pickle.Pickler.save_dict = save_dict_sorted
|
||||
|
||||
# Use dill to recursively pickle the provider and store base64 encoded form
|
||||
pty = type(provider)
|
||||
oldptymod = pty.__module__
|
||||
try:
|
||||
# TODO[uqfoundation/dill#424]: Dill currently only serializes classes by value when they are in `__main__`.
|
||||
# Since we need to ensure classes are serialized by value for dynamic provider serialization to work, we
|
||||
# for now will overwrite the `__module__` to be `__main__` on the provider class. When uqfoundation/dill#424
|
||||
# is addressed, we may be able to accomplish the desired results in a less invasive way.
|
||||
pty.__module__ = '__main__'
|
||||
byts = dill.dumps(provider, protocol=pickle.DEFAULT_PROTOCOL, recurse=True)
|
||||
return base64.b64encode(byts).decode('utf-8')
|
||||
finally:
|
||||
pty.__module__ = oldptymod
|
||||
# Restore the original pickler
|
||||
pickle.Pickler = old_pickler
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
*.pyc
|
||||
/.pulumi/
|
||||
/dist/
|
||||
/*.egg-info
|
|
@ -1,3 +0,0 @@
|
|||
name: dynamic_py
|
||||
description: A simple Python program that uses dynamic providers.
|
||||
runtime: python
|
|
@ -1,7 +0,0 @@
|
|||
# Copyright 2016-2021, Pulumi Corporation. All rights reserved.
|
||||
|
||||
from pulumi import export
|
||||
from other import r
|
||||
|
||||
export("random_id", r.id)
|
||||
export("random_val", r.val)
|
|
@ -1,20 +0,0 @@
|
|||
# Copyright 2016-2021, Pulumi Corporation. All rights reserved.
|
||||
|
||||
import binascii
|
||||
import os
|
||||
from pulumi.dynamic import Resource, ResourceProvider, CreateResult
|
||||
|
||||
# Define the dynamic provider and create the dynamic provider resource from a
|
||||
# file that is not `__main__` per pulumi/pulumi#7453.
|
||||
|
||||
class RandomResourceProvider(ResourceProvider):
|
||||
def create(self, props):
|
||||
val = binascii.b2a_hex(os.urandom(15)).decode("ascii")
|
||||
return CreateResult(val, { "val": val })
|
||||
|
||||
class Random(Resource):
|
||||
val: str
|
||||
def __init__(self, name, opts = None):
|
||||
super().__init__(RandomResourceProvider(), name, {"val": ""}, opts)
|
||||
|
||||
r = Random("foo")
|
|
@ -407,15 +407,6 @@ func TestDynamicPython(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestDynamicPythonNonMain(t *testing.T) {
|
||||
integration.ProgramTest(t, &integration.ProgramTestOptions{
|
||||
Dir: filepath.Join("dynamic", "python-non-main"),
|
||||
Dependencies: []string{
|
||||
filepath.Join("..", "..", "sdk", "python", "env", "src"),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Tests custom resource type name of dynamic provider in Python.
|
||||
func TestCustomResourceTypeNameDynamicPython(t *testing.T) {
|
||||
integration.ProgramTest(t, &integration.ProgramTestOptions{
|
||||
|
|
Loading…
Reference in a new issue