Skip to content

Commit 3acaa59

Browse files
authored
fix(update_provider_when_message_created): Fix db transaction (#21503)
Signed-off-by: -LAN- <laipz8200@outlook.com>
1 parent 2d5cdbe commit 3acaa59

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

api/events/event_handlers/update_provider_when_message_created.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pydantic import BaseModel
77
from sqlalchemy import update
8+
from sqlalchemy.orm import Session
89

910
from configs import dify_config
1011
from core.app.entities.app_invoke_entities import AgentChatAppGenerateEntity, ChatAppGenerateEntity
@@ -183,7 +184,7 @@ def _execute_provider_updates(updates_to_perform: list[_ProviderUpdateOperation]
183184

184185
# Use SQLAlchemy's context manager for transaction management
185186
# This automatically handles commit/rollback
186-
with db.session.begin():
187+
with Session(db.engine) as session:
187188
# Use a single transaction for all updates
188189
for update_operation in updates_to_perform:
189190
filters = update_operation.filters
@@ -214,7 +215,7 @@ def _execute_provider_updates(updates_to_perform: list[_ProviderUpdateOperation]
214215

215216
# Build and execute the update statement
216217
stmt = update(Provider).where(*where_conditions).values(**update_values)
217-
result = db.session.execute(stmt)
218+
result = session.execute(stmt)
218219
rows_affected = result.rowcount
219220

220221
logger.debug(

0 commit comments

Comments
 (0)