fix(update_provider_when_message_created): Fix db transaction (#21503)
Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@@ -5,6 +5,7 @@ from typing import Any, Optional
|
|||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from sqlalchemy import update
|
from sqlalchemy import update
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from configs import dify_config
|
from configs import dify_config
|
||||||
from core.app.entities.app_invoke_entities import AgentChatAppGenerateEntity, ChatAppGenerateEntity
|
from core.app.entities.app_invoke_entities import AgentChatAppGenerateEntity, ChatAppGenerateEntity
|
||||||
@@ -183,7 +184,7 @@ def _execute_provider_updates(updates_to_perform: list[_ProviderUpdateOperation]
|
|||||||
|
|
||||||
# Use SQLAlchemy's context manager for transaction management
|
# Use SQLAlchemy's context manager for transaction management
|
||||||
# This automatically handles commit/rollback
|
# This automatically handles commit/rollback
|
||||||
with db.session.begin():
|
with Session(db.engine) as session:
|
||||||
# Use a single transaction for all updates
|
# Use a single transaction for all updates
|
||||||
for update_operation in updates_to_perform:
|
for update_operation in updates_to_perform:
|
||||||
filters = update_operation.filters
|
filters = update_operation.filters
|
||||||
@@ -214,7 +215,7 @@ def _execute_provider_updates(updates_to_perform: list[_ProviderUpdateOperation]
|
|||||||
|
|
||||||
# Build and execute the update statement
|
# Build and execute the update statement
|
||||||
stmt = update(Provider).where(*where_conditions).values(**update_values)
|
stmt = update(Provider).where(*where_conditions).values(**update_values)
|
||||||
result = db.session.execute(stmt)
|
result = session.execute(stmt)
|
||||||
rows_affected = result.rowcount
|
rows_affected = result.rowcount
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
Reference in New Issue
Block a user