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: fix-app-site-missing command (#5714)

takatost8e5569f77328
diff --git a/api/commands.py b/api/commands.py
index fa6221df52a..56217c898e2 100644
--- a/api/commands.py
+++ b/api/commands.py
@@ -593,17 +593,22 @@ def fix_app_site_missing():
"""
click.echo(click.style('Start fix app related site missing issue.', fg='green'))
+ failed_app_ids = []
while True:
- try:
- sql = """select apps.id as id from apps left join sites on sites.app_id=apps.id
+ sql = """select apps.id as id from apps left join sites on sites.app_id=apps.id
where sites.id is null limit 1000"""
- with db.engine.begin() as conn:
- rs = conn.execute(db.text(sql))
+ with db.engine.begin() as conn:
+ rs = conn.execute(db.text(sql))
+
+ processed_count = 0
+ for i in rs:
+ processed_count += 1
+ app_id = str(i.id)
+
+ if app_id in failed_app_ids:
+ continue
- processed_count = 0
- for i in rs:
- processed_count += 1
- app_id = str(i.id)
+ try:
app = db.session.query(App).filter(App.id == app_id).first()
tenant = app.tenant
if tenant:
@@ -615,13 +620,15 @@ where sites.id is null limit 1000"""
account = accounts[0]
print("Fix app {} related site missing issue.".format(app.id))
app_was_created.send(app, account=account)
+ except Exception as e:
+ failed_app_ids.append(app_id)
+ click.echo(click.style('Fix app {} related site missing issue failed!'.format(app_id), fg='red'))
+ logging.exception(f'Fix app related site missing issue failed, error: {e}')
+ continue
+
+ if not processed_count:
+ break
- if not processed_count:
- break
- except Exception as e:
- click.echo(click.style('Fix app related site missing issue failed!', fg='red'))
- logging.exception(f'Fix app related site missing issue failed, error: {e}')
- continue
click.echo(click.style('Congratulations! Fix app related site missing issue successful!', fg='green'))