Repository navigation
fix(tools): use short-lived sessions for icon lookups to prevent idle-in-transaction - #36903
Merged
fatelei merged 2 commits intoJun 2, 2026
Conversation
…-in-transaction Replace db.session (long-lived Flask SQLAlchemy session bound to request context) with explicit Session(db.engine) context managers in: - generate_workflow_tool_icon_url() - generate_api_tool_icon_url() This prevents the database transaction from remaining open while a nested Workflow Tool or API Tool executes long-running HTTP/LLM calls, which causes PostgreSQL connections to stay 'idle in transaction' for minutes until idle_in_transaction_session_timeout kills them. The MCP tool icon URL already uses the same pattern; this change brings workflow and API tools into alignment. Fixes langgenius#36902
goingforstudying-ctrl
requested review from
QuantumGhost and
laipz8200
as code owners
June 1, 2026 14:07
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-06-02 01:41:47.105793986 +0000
+++ /tmp/pyrefly_pr.txt 2026-06-02 01:41:34.142700929 +0000
@@ -67,7 +67,7 @@
ERROR Class member `PluginToolProviderController.entity` overrides parent class `BuiltinToolProviderController` in an inconsistent manner [bad-override-mutable-attribute]
--> core/tools/plugin_tool/provider.py:12:5
ERROR Cannot set item in `dict[str, dict[str, Any]]` [unsupported-operation]
- --> core/tools/tool_manager.py:1110:58
+ --> core/tools/tool_manager.py:1117:58
ERROR `(method: str, url: str, max_retries: int = ..., **kwargs: Any) -> httpx._models.Response` is not assignable to attribute `perform_request` with type `(self: CloudScraper, method: Unknown, url: Unknown, *args: Unknown, **kwargs: Unknown) -> requests.models.Response` [bad-assignment]
--> core/tools/utils/web_reader_tool.py:66:35
ERROR `list[Never]` is not assignable to attribute `tools` with type `Never` [bad-assignment]
@@ -5340,11 +5340,11 @@
ERROR Argument `Literal['']` is not assignable to parameter `typ` with type `Literal['api', 'builtin', 'mcp', 'workflow'] | None` in function `core.tools.tool_manager.ToolManager.list_providers_from_api` [bad-argument-type]
--> tests/unit_tests/core/tools/test_tool_manager.py:678:97
ERROR `SimpleNamespace` is not assignable to attribute `entity` with type `ToolProviderEntityWithPlugin` [bad-assignment]
- --> tests/unit_tests/core/tools/test_tool_manager.py:820:30
+ --> tests/unit_tests/core/tools/test_tool_manager.py:839:30
ERROR `SimpleNamespace` is not assignable to attribute `entity` with type `ToolProviderEntityWithPlugin` [bad-assignment]
- --> tests/unit_tests/core/tools/test_tool_manager.py:844:30
+ --> tests/unit_tests/core/tools/test_tool_manager.py:863:30
ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/core/tools/test_tool_manager.py:849:20
+ --> tests/unit_tests/core/tools/test_tool_manager.py:868:20
ERROR Argument `SimpleNamespace` is not assignable to parameter `controller` with type `ToolProviderController` in function `core.tools.utils.encryption.create_tool_provider_encrypter` [bad-argument-type]
--> tests/unit_tests/core/tools/utils/test_encryption.py:203:75
ERROR `None` is not subscriptable [unsupported-operation]
|
Contributor
Pyrefly Type Coverage
|
fatelei
approved these changes
Jun 2, 2026
6 tasks done
2 of 4 tasks
Ssazurov
pushed a commit
to Ssazurov/dify
that referenced
this pull request
Aug 8, 2026
…-in-transaction (langgenius#36903) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #36902
Replace db.session with explicit Session(db.engine) context managers in generate_workflow_tool_icon_url() and generate_api_tool_icon_url().
This prevents DB transactions from remaining open during long-running nested workflow execution, which causes PostgreSQL connections to stay 'idle in transaction' for minutes.
The MCP tool icon URL already uses this pattern; this brings workflow and API tools into alignment.