Repository navigation
refactor(api): drop global db.session from workflow run trace assembly - #45679
Merged
fatelei merged 3 commits intoNov 6, 2026
Merged
Conversation
WorkflowRunService already receives a session factory at construction. Use it for the creator lookups in get_workflow_run_node_executions and get_workflow_tool_node_executions instead of the Flask-SQLAlchemy global session, and drop the now-unused db import. The session is closed before the traces are returned; the response models only read column-backed Account/EndUser fields, which stay readable on detached instances (expire_on_commit=False, no commit). Part of langgenius#45584. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-05 17:10:12.661451197 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-05 17:09:52.410303029 +0000
@@ -6116,6 +6116,10 @@
--> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:162:21
ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `full_process_data` with type `dict[str, object] | None` in function `_repository` [bad-argument-type]
--> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:162:49
+ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `process_data` with type `dict[str, object]` in function `_execution` [bad-argument-type]
+ --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:182:25
+ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `full_process_data` with type `dict[str, object] | None` in function `_repository` [bad-argument-type]
+ --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:182:53
ERROR Argument `_RepoRecorder | Unknown` is not assignable to parameter `workflow_execution_repository` with type `WorkflowExecutionRepository` in function `services.workflow_persistence.WorkflowPersistenceLayer.__init__` [bad-argument-type]
--> tests/unit_tests/services/test_workflow_persistence.py:356:39
ERROR Argument `_RepoRecorder | Unknown` is not assignable to parameter `workflow_node_execution_repository` with type `WorkflowNodeExecutionRepository` in function `services.workflow_persistence.WorkflowPersistenceLayer.__init__` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45679 +/- ##
=======================================
Coverage 89.97% 89.97%
=======================================
Files 6260 6260
Lines 391690 391691 +1
Branches 78479 78479
=======================================
+ Hits 352435 352442 +7
+ Misses 33164 33160 -4
+ Partials 6091 6089 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Replace the spec-based session mocks and the MagicMock assembler with a close-tracking Session subclass and a recording function, so the test satisfies the no-spec-mock, no-new-session-mock and no-new-mock guards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Hi @asukaminato0721 @QuantumGhost, can you please help to review this PR then? |
fatelei
approved these changes
Nov 6, 2026
fatelei
pushed a commit
to fatelei/dify
that referenced
this pull request
Nov 9, 2026
langgenius#45679) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.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.
Important
Fixes #<issue number>.Summary
Part of #45584. This PR covers
services/workflow_run_service.pyonly. It does not overlap with #45587, which handlesapi_tools_manage_service.py.tasks/initialize_created_app_rbac_access_task.pywill follow in a separate PR.WorkflowRunServicealready receives asession_factoryat construction, andget_workflow_run_pause_detailsalready uses it. The two node-execution trace methods were the last places in the service that still passed the Flask-SQLAlchemy globaldb.session()toassemble_workflow_node_execution_traces.get_workflow_run_node_executionsandget_workflow_tool_node_executionsnow resolve creators insidewith self._session_factory() as session:. The session closes before the method returns. For tool traces, the internal correlation keys are stripped fromprocess_dataafter the session has closed.from extensions.ext_database import dbimport is removed.Session lifetime: the session is only used for read-only
session.get(Account | EndUser, ...)lookups and is never committed.database_clientis configured withexpire_on_commit=False. The node-execution response models only read the column-backedSimpleAccount(id,name,email) andSimpleEndUserfields. These remain readable on the detached instances after the session closes. A new test serializes the response after the session closes to lock this in.Tests
test_trace_assembly_uses_a_session_from_the_injected_factory, parametrized over both methods: thesessionpassed to the assembler comes from the injected factory, and the factory's context is exited.test_traces_serialize_creator_after_the_assembly_session_closes: stores anAccountin SQLite, assembles traces in a session that is then closed, and validatesWorkflowRunNodeExecutionListResponse.pytest api/tests/unit_tests/services/test_workflow_run_service.py api/tests/unit_tests/services/test_workflow_node_execution_trace_service.py api/tests/unit_tests/controllers/console/app/test_workflow_run.py: 37 passed.Screenshots
N/A (no UI change)
Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods🤖 Generated with Claude Code
From Claude Code