fix: app token's last_used_at can't be updated when last_used_at is null (#12770)

This commit is contained in:
EricPan 2025-01-22 11:01:45 +08:00 committed by GitHub
parent e09f6e4987
commit 05a0faff6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -195,7 +195,11 @@ def validate_and_get_api_token(scope: str | None = None):
with Session(db.engine, expire_on_commit=False) as session:
update_stmt = (
update(ApiToken)
.where(ApiToken.token == auth_token, ApiToken.last_used_at < cutoff_time, ApiToken.type == scope)
.where(
ApiToken.token == auth_token,
(ApiToken.last_used_at.is_(None) | (ApiToken.last_used_at < cutoff_time)),
ApiToken.type == scope,
)
.values(last_used_at=current_time)
.returning(ApiToken)
)