Skip to content
Open
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
1 change: 1 addition & 0 deletions changes/10732.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix AttributeError in v2 login CLI when server returns a string in the data field (BA-5559)
19 changes: 17 additions & 2 deletions src/ai/backend/client/cli/v2/login_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,30 @@ async def _run() -> None:
async with client.session.post(login_url, json=payload) as resp:
data = await resp.json()

def _get_details(resp_data: dict[str, Any]) -> str:
raw = resp_data.get("data")
if isinstance(raw, dict):
details = raw.get("details")
if details:
return str(details)
elif raw:
return str(raw)
# Handle RFC 7807 problem responses (e.g., {"type": ..., "title": ...})
if "title" in resp_data:
return str(resp_data["title"])
return "Unknown error"

if not data.get("authenticated"):
if data.get("data", {}).get("details") == "OTP not provided":
details = _get_details(data)

if details == "OTP not provided":
otp = input("One-time Password: ")
payload["otp"] = otp.strip()
async with client.session.post(login_url, json=payload) as resp:
data = await resp.json()

if not data.get("authenticated"):
details = data.get("data", {}).get("details", "Unknown error")
details = _get_details(data)
click.echo(click.style(f"Login failed: {details}", fg="red"))
raise SystemExit(1)

Expand Down
Loading