fix: type-narrow session_id in _terminate_and_mark (mypy)

Defensive: if both `session_id` and `id` are missing, return early. The
str-cast keeps mypy happy when the row uses a UUID-typed column.

LIT-2878
This commit is contained in:
Ishaan Jaff 2026-05-06 15:31:05 -07:00
parent 2dc9b255f2
commit b25dd8b716
No known key found for this signature in database

View file

@ -101,7 +101,11 @@ async def _terminate_and_mark(
prisma_client: Any,
) -> None:
"""Common path: terminate VM, update session row. Idempotent."""
session_id = getattr(session, "session_id", None) or getattr(session, "id", None)
session_id_raw = getattr(session, "session_id", None) or getattr(session, "id", None)
if not session_id_raw:
# Defensive: row without an id cannot be updated.
return
session_id: str = str(session_id_raw)
# Re-fetch the row to confirm status hasn't moved (cheap optimistic lock).
fresh = None