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.

improve the readability of the function generate_api_key (#12552)

gakkiyomi989fb11fd715
diff --git a/api/models/model.py b/api/models/model.py
index d2d4d5853fd..d6f73c5ede8 100644
--- a/api/models/model.py
+++ b/api/models/model.py
@@ -1405,9 +1405,8 @@ class ApiToken(db.Model): # type: ignore[name-defined]
def generate_api_key(prefix, n):
while True:
result = prefix + generate_string(n)
- while db.session.query(ApiToken).filter(ApiToken.token == result).count() > 0:
- result = prefix + generate_string(n)
-
+ if db.session.query(ApiToken).filter(ApiToken.token == result).count() > 0:
+ continue
return result