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

fix go back to acct for prefect cloud login and prefect cloud workspace set #17296

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/prefect/cli/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ def prompt_select_from_list(
Returns:
str: the selected option
"""

current_idx = 0
selected_option = None

Expand Down Expand Up @@ -243,12 +242,16 @@ def build_table() -> Table:
exit_with_error("")
elif key == readchar.key.ENTER or key == readchar.key.CR:
selected_option = options[current_idx]
if isinstance(selected_option, tuple):
selected_option = selected_option[0]
# Break out of the loop immediately after setting selected_option
break

live.update(build_table(), refresh=True)

return selected_option
# Convert tuple to its first element if needed
if isinstance(selected_option, tuple):
selected_option = selected_option[0]

return selected_option


async def login_with_browser() -> str:
Expand Down Expand Up @@ -364,11 +367,13 @@ async def _prompt_for_account_and_workspace(
None,
"[bold]Go back to account selection[/bold]",
)

result = prompt_select_from_list(
app.console,
"Which workspace would you like to use?",
options=workspace_options + [go_back_option],
)

if not result:
return None, True
else:
Expand Down Expand Up @@ -688,10 +693,22 @@ async def set(
if not workspaces:
exit_with_error("No workspaces found in the selected account.")

# Store the original list of workspaces
original_workspaces = workspaces.copy()

go_back = True
workspace = None
loop_count = 0

while go_back:
loop_count += 1

# If we're going back, use the original list of workspaces
if loop_count > 1:
workspaces = original_workspaces.copy()

workspace, go_back = await _prompt_for_account_and_workspace(workspaces)

if workspace is None:
exit_with_error("No workspace selected.")

Expand Down
Loading