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
feat: support SQLALCHEMY_POOL_RESET_ON_RETURN config (#31156)
wangxiaolei8132c444dc83
diff --git a/api/.env.example b/api/.env.exampleindex f6f65011ea1..bec3c67ac89 100644--- a/api/.env.example+++ b/api/.env.example@@ -98,6 +98,8 @@ DB_DATABASE=difySQLALCHEMY_POOL_PRE_PING=trueSQLALCHEMY_POOL_TIMEOUT=30+# Connection pool reset behavior on return+SQLALCHEMY_POOL_RESET_ON_RETURN=rollback# Storage configuration# use for store upload files, private keys...diff --git a/api/configs/middleware/__init__.py b/api/configs/middleware/__init__.pyindex c392b8840f2..ee8b93aa9fc 100644--- a/api/configs/middleware/__init__.py+++ b/api/configs/middleware/__init__.py@@ -114,7 +114,7 @@ class SQLAlchemyEngineOptionsDict(TypedDict):pool_pre_ping: boolconnect_args: dict[str, str]pool_use_lifo: bool- pool_reset_on_return: None+ pool_reset_on_return: Literal["commit", "rollback", None]pool_timeout: int@@ -223,6 +223,11 @@ class DatabaseConfig(BaseSettings):default=30,)+ SQLALCHEMY_POOL_RESET_ON_RETURN: Literal["commit", "rollback", None] = Field(+ description="Connection pool reset behavior on return. Options: 'commit', 'rollback', or None",+ default="rollback",+ )+RETRIEVAL_SERVICE_EXECUTORS: NonNegativeInt = Field(description="Number of processes for the retrieval service, default to CPU cores.",default=os.cpu_count() or 1,@@ -252,7 +257,7 @@ class DatabaseConfig(BaseSettings):"pool_pre_ping": self.SQLALCHEMY_POOL_PRE_PING,"connect_args": connect_args,"pool_use_lifo": self.SQLALCHEMY_POOL_USE_LIFO,- "pool_reset_on_return": None,+ "pool_reset_on_return": self.SQLALCHEMY_POOL_RESET_ON_RETURN,"pool_timeout": self.SQLALCHEMY_POOL_TIMEOUT,}return resultdiff --git a/api/tests/unit_tests/configs/test_dify_config.py b/api/tests/unit_tests/configs/test_dify_config.pyindex bad246a4bb1..57dbf453ded 100644--- a/api/tests/unit_tests/configs/test_dify_config.py+++ b/api/tests/unit_tests/configs/test_dify_config.py@@ -114,8 +114,8 @@ def test_flask_configs(monkeypatch: pytest.MonkeyPatch):"pool_recycle": 3600,"pool_size": 30,"pool_use_lifo": False,- "pool_reset_on_return": None,"pool_timeout": 30,+ "pool_reset_on_return": "rollback",}assert config["CONSOLE_WEB_URL"] == "https://example.com"diff --git a/docker/.env.example b/docker/.env.exampleindex 122228cdd12..5871cacc395 100644--- a/docker/.env.example+++ b/docker/.env.example@@ -268,6 +268,8 @@ SQLALCHEMY_POOL_USE_LIFO=false# Number of seconds to wait for a connection from the pool before raising a timeout error.# Default is 30SQLALCHEMY_POOL_TIMEOUT=30+# Connection pool reset behavior on return+SQLALCHEMY_POOL_RESET_ON_RETURN=rollback# Maximum number of connections to the database# Default is 100diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yamlindex 6dcab4a9fc0..56f657f7a73 100644--- a/docker/docker-compose.yaml+++ b/docker/docker-compose.yaml@@ -70,6 +70,7 @@ x-shared-env: &shared-api-worker-envSQLALCHEMY_POOL_PRE_PING: ${SQLALCHEMY_POOL_PRE_PING:-false}SQLALCHEMY_POOL_USE_LIFO: ${SQLALCHEMY_POOL_USE_LIFO:-false}SQLALCHEMY_POOL_TIMEOUT: ${SQLALCHEMY_POOL_TIMEOUT:-30}+ SQLALCHEMY_POOL_RESET_ON_RETURN: ${SQLALCHEMY_POOL_RESET_ON_RETURN:-rollback}POSTGRES_MAX_CONNECTIONS: ${POSTGRES_MAX_CONNECTIONS:-200}POSTGRES_SHARED_BUFFERS: ${POSTGRES_SHARED_BUFFERS:-128MB}POSTGRES_WORK_MEM: ${POSTGRES_WORK_MEM:-4MB}