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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
Fix incorrect exception handling in db query (#23582)
Yongtao Huangc8c591d73cb3
diff --git a/api/commands.py b/api/commands.pyindex 8177f1a48c8..8ee52ba7162 100644--- a/api/commands.py+++ b/api/commands.py@@ -9,7 +9,7 @@ import sqlalchemy as safrom flask import current_appfrom pydantic import TypeAdapterfrom sqlalchemy import select-from werkzeug.exceptions import NotFound+from sqlalchemy.exc import SQLAlchemyErrorfrom configs import dify_configfrom constants.languages import languages@@ -181,8 +181,8 @@ def migrate_annotation_vector_database():)if not apps:break- except NotFound:- break+ except SQLAlchemyError:+ raisepage += 1for app in apps:@@ -308,8 +308,8 @@ def migrate_knowledge_vector_database():)datasets = db.paginate(select=stmt, page=page, per_page=50, max_per_page=50, error_out=False)- except NotFound:- break+ except SQLAlchemyError:+ raisepage += 1for dataset in datasets:@@ -561,8 +561,8 @@ def old_metadata_migration():.order_by(DatasetDocument.created_at.desc()))documents = db.paginate(select=stmt, page=page, per_page=50, max_per_page=50, error_out=False)- except NotFound:- break+ except SQLAlchemyError:+ raiseif not documents:breakfor document in documents:diff --git a/api/schedule/clean_embedding_cache_task.py b/api/schedule/clean_embedding_cache_task.pyindex 2298acf6ebe..2b74fb2dd04 100644--- a/api/schedule/clean_embedding_cache_task.py+++ b/api/schedule/clean_embedding_cache_task.py@@ -3,7 +3,7 @@ import timeimport clickfrom sqlalchemy import text-from werkzeug.exceptions import NotFound+from sqlalchemy.exc import SQLAlchemyErrorimport appfrom configs import dify_config@@ -27,8 +27,8 @@ def clean_embedding_cache_task():.all())embedding_ids = [embedding_id[0] for embedding_id in embedding_ids]- except NotFound:- break+ except SQLAlchemyError:+ raiseif embedding_ids:for embedding_id in embedding_ids:db.session.execute(diff --git a/api/schedule/clean_messages.py b/api/schedule/clean_messages.pyindex 4c357459598..a896c818a5d 100644--- a/api/schedule/clean_messages.py+++ b/api/schedule/clean_messages.py@@ -3,7 +3,7 @@ import loggingimport timeimport click-from werkzeug.exceptions import NotFound+from sqlalchemy.exc import SQLAlchemyErrorimport appfrom configs import dify_config@@ -42,8 +42,8 @@ def clean_messages():.all())- except NotFound:- break+ except SQLAlchemyError:+ raiseif not messages:breakfor message in messages:diff --git a/api/schedule/clean_unused_datasets_task.py b/api/schedule/clean_unused_datasets_task.pyindex 7887835bc58..940da5309e6 100644--- a/api/schedule/clean_unused_datasets_task.py+++ b/api/schedule/clean_unused_datasets_task.py@@ -3,7 +3,7 @@ import timeimport clickfrom sqlalchemy import func, select-from werkzeug.exceptions import NotFound+from sqlalchemy.exc import SQLAlchemyErrorimport appfrom configs import dify_config@@ -65,8 +65,8 @@ def clean_unused_datasets_task():datasets = db.paginate(stmt, page=1, per_page=50)- except NotFound:- break+ except SQLAlchemyError:+ raiseif datasets.items is None or len(datasets.items) == 0:breakfor dataset in datasets:@@ -146,8 +146,8 @@ def clean_unused_datasets_task():)datasets = db.paginate(stmt, page=1, per_page=50)- except NotFound:- break+ except SQLAlchemyError:+ raiseif datasets.items is None or len(datasets.items) == 0:breakfor dataset in datasets:diff --git a/api/services/workflow_draft_variable_service.py b/api/services/workflow_draft_variable_service.pyindex 2d62d49d915..6bbb3bca040 100644--- a/api/services/workflow_draft_variable_service.py+++ b/api/services/workflow_draft_variable_service.py@@ -256,7 +256,7 @@ class WorkflowDraftVariableService:def _reset_node_var_or_sys_var(self, workflow: Workflow, variable: WorkflowDraftVariable) -> WorkflowDraftVariable | None:- # If a variable does not allow updating, it makes no sence to resetting it.+ # If a variable does not allow updating, it makes no sense to reset it.if not variable.editable:return variable# No execution record for this variable, delete the variable instead.@@ -478,7 +478,7 @@ def _batch_upsert_draft_variable("node_execution_id": stmt.excluded.node_execution_id,},)- elif _UpsertPolicy.IGNORE:+ elif policy == _UpsertPolicy.IGNORE:stmt = stmt.on_conflict_do_nothing(index_elements=WorkflowDraftVariable.unique_app_id_node_id_name())else:raise Exception("Invalid value for update policy.")