fix STALE token with malformed value falling to ValueError instead of refresh

When token_state is STALE but the token is None/non-string, downgrade
token_state to INVALID so the blocking refresh path executes instead of
skipping it and hitting the final ValueError.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Krrish Dholakia 2026-05-13 14:15:29 -07:00
parent 5c1e3ff245
commit b9a5ca6efb

View file

@ -894,9 +894,9 @@ class VertexBase:
raise ValueError("Could not resolve project_id")
current_token = _credentials.token
if current_token is None or not isinstance(current_token, str):
# Token is malformed despite STALE state — fall through
# to INVALID path which will block on a full refresh.
pass
# Token is malformed despite STALE state — downgrade to
# INVALID so the next block performs a blocking refresh.
token_state = TokenState.INVALID
else:
# Schedule a single background refresh — skip if one is
# already in flight for this credential key.