Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

EricPan05a0faff6ac3
diff --git a/api/controllers/service_api/wraps.py b/api/controllers/service_api/wraps.py
index fc4cce48769..c746944be1a 100644
--- a/api/controllers/service_api/wraps.py
+++ b/api/controllers/service_api/wraps.py
@@ -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)
)