You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 29, 2026. It is now read-only.
OAuthTokenAuthentication has a Pydantic mode=\"after\" validator that raises ValueError(\"Token has already expired\") whenever expires_at is in the past:
# backend/airweave/schemas/source_connection.py@model_validator(mode="after")defvalidate_token(self):
ifself.expires_atandself.expires_at<datetime.now(timezone.utc):
raiseValueError("Token has already expired")
returnself
Problem
OAuth access tokens expire (typically in 1 hour). The normal flow for long-lived connections is:
Store the token (including expires_at) in the DB.
On the next sync, load the token from DB.
Detect that expires_at < now(), then call the refresh endpoint.
Swap in the new access token.
Step 2 fails: constructing OAuthTokenAuthentication from the persisted data triggers the validator and raises a ValidationErrorbefore the code ever gets a chance to refresh. This means any source connection whose access token has expired cannot be loaded at all — syncs will fail with a Pydantic ValidationError rather than a meaningful "token expired, refresh needed" error.
Expected behaviour
The expiry check should guard connection creation / user-facing input, not the internal load-for-refresh path. Options:
Move the check out of the model validator and into the OAuth handshake layer so it only fires when a brand-new token is being accepted, not when an existing one is being deserialized.
Alternatively, make the validator configurable (e.g., a skip_expiry_check flag) or split into two schemas: OAuthTokenInput (strict, validates freshness) and OAuthTokenStored (no expiry check).
Steps to reproduce
fromdatetimeimportdatetime, timezone, timedeltafromairweave.schemas.source_connectionimportOAuthTokenAuthentication# Simulate loading a token that expired 10 minutes agoOAuthTokenAuthentication(
access_token="some-access-token",
expires_at=datetime.now(timezone.utc) -timedelta(minutes=10),
)
# → raises pydantic.ValidationError: Token has already expired
Impact
Any OAuth-backed source connection whose access token has expired will fail to load for refresh, causing syncs to break instead of transparently refreshing.
Summary
OAuthTokenAuthenticationhas a Pydanticmode=\"after\"validator that raisesValueError(\"Token has already expired\")wheneverexpires_atis in the past:Problem
OAuth access tokens expire (typically in 1 hour). The normal flow for long-lived connections is:
expires_at) in the DB.expires_at < now(), then call the refresh endpoint.Step 2 fails: constructing
OAuthTokenAuthenticationfrom the persisted data triggers the validator and raises aValidationErrorbefore the code ever gets a chance to refresh. This means any source connection whose access token has expired cannot be loaded at all — syncs will fail with a PydanticValidationErrorrather than a meaningful "token expired, refresh needed" error.Expected behaviour
The expiry check should guard connection creation / user-facing input, not the internal load-for-refresh path. Options:
skip_expiry_checkflag) or split into two schemas:OAuthTokenInput(strict, validates freshness) andOAuthTokenStored(no expiry check).Steps to reproduce
Impact
Any OAuth-backed source connection whose access token has expired will fail to load for refresh, causing syncs to break instead of transparently refreshing.