diff --git a/changelog/pending/20221021--sdk-python--pulumi-automation-create_or_select_stack-attempts-to-select-the-stack-before-attempting-to-create.yaml b/changelog/pending/20221021--sdk-python--pulumi-automation-create_or_select_stack-attempts-to-select-the-stack-before-attempting-to-create.yaml new file mode 100644 index 000000000000..25d6599a89ff --- /dev/null +++ b/changelog/pending/20221021--sdk-python--pulumi-automation-create_or_select_stack-attempts-to-select-the-stack-before-attempting-to-create.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: sdk/python + description: pulumi.automation.create_or_select_stack() attempts to select the stack before attempting to create diff --git a/sdk/python/lib/pulumi/automation/_stack.py b/sdk/python/lib/pulumi/automation/_stack.py index 00b86bc038ad..6c59d64586a0 100644 --- a/sdk/python/lib/pulumi/automation/_stack.py +++ b/sdk/python/lib/pulumi/automation/_stack.py @@ -25,7 +25,7 @@ from ._cmd import CommandResult, _run_pulumi_cmd, OnOutput from ._config import ConfigValue, ConfigMap -from .errors import StackAlreadyExistsError +from .errors import StackAlreadyExistsError, StackNotFoundError from .events import OpMap, EngineEvent, SummaryEvent from ._output import OutputMap from ._server import LanguageServer @@ -186,9 +186,9 @@ def __init__(self, name: str, workspace: Workspace, mode: StackInitMode) -> None workspace.select_stack(name) elif mode is StackInitMode.CREATE_OR_SELECT: try: - workspace.create_stack(name) - except StackAlreadyExistsError: workspace.select_stack(name) + except StackNotFoundError: + workspace.create_stack(name) def __repr__(self): return f"Stack(stack_name={self.name!r}, workspace={self.workspace!r}, mode={self._mode!r})"