-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support better previews in Python by mocking out Unknown values #1482
Conversation
Here's an example where I preview a use of Before:
After:
|
Not having looked at the code yet, I strongly vote for taking this. Seems like a huge step forward in the absence of having true outputs. I shall take a look at the code now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, let's get this in for the final release.
Agreed. I think we should also take pulumi/pulumi-terraform#171, it's a major annoyance for Python use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
thanks! |
this is a practical and Pythonic solution. Nice! lgtm. |
This PR is a little wacky, and I totally understand if we don't want to take it, but it results in a much better preview experience for Python.
@pgavlin suggested the other day that the Python Unknown value be just the string
<computed>
. This PR is basically an elaboration on this idea that addresses some of the practical concerns that come out of it.In JavaScript, we use
Output
to hide the existence of Unknown values. In this way we can prevent the user from ever observing an unknown value, since we don't runapply
callbacks on previews. Python does not haveOutput
(yet) so there's nothing stopping unknown values from leaking into user programs during previews.It's not an awful thing for users to observe unknown values. An unknown value, though, should
tfgen
-generated code - usually asserting that a value is a string, a list, or a dictUnknown
elsewhere in the runtime, so it can be turned in to the unknown sentinel GUID before being sent to the engine.This PR accomplishes all but the second two parts of 3 (masquerading as a list or dict) by defining an
Unknown
class that inherits fromunicode
and lies about its internals:Unknown
to a string (e.g. by printing it or callingstr
on it) produces the string"computed"
. This allows users to safely treatUnknown
as a string for concatenation, printing, or formatting.Unknown
to a boolean (e.g. by usingnot
with it or using it in a conditional. This passes all required argument presence checks intfgen
-generated code.Unknown
produces anotherUnknown
, regardless of the property. This allowsUnknown
to masquerade as a resource.Unknown
produces anotherUnknown
, which allowsUnknown
to masquerade as lists and dicts.Unknown
produces an empty iterator.With this object, we're able to do nontrivial previews on Python programs, as long as the preview does not attempt to use
Unknown
as a list or dict.Unknown
inherits fromunicode
, the unicode string type, so it passes alltfgen
checks that a property is a string, but it does not passisinstance(..., list)
orisinstance(..., dict
).