You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, there's still significant remaining work. Here's a summary of where things stand and what's next:
Current Status: The migration is a two-stage process — Stage 1 replaces db.session with Session(db.engine)[1], and Stage 2 further optimizes to sessionmaker().begin() which handles commit/rollback automatically [2]. Good progress has been made recently (~7 PRs merged in the last few weeks), but ~150–200 files still need conversion.
Hi, @asukaminato0721. I'm Dosu, and I'm helping the dify team manage their backlog and am marking this issue as stale.
Recap
You proposed refactoring the codebase to use SQLAlchemy’s engine directly, such as Session(db.engine), as part of the broader effort to remove flask_sqlalchemy.
Yes. As of the November 4 checkout, these files still have direct db.session usage beyond cleanup. Paths are relative to api/; this is a verified shortlist, not an exhaustive backlog:
Passes db.session() into provider construction. [5]
services/tools/tools_transform_service.py
Uses the global session for provider construction and user lookups. [6][7]
services/workflow_run_service.py
Passes db.session() into execution-trace assembly. [8]
models/workflow.py
_resolve_workflow_app_tenant_id() queries through the global session. [9]
tasks/initialize_created_app_rbac_access_task.py
Owner lookup and resource batching use db.session(). [10][11]
I’d start with the two tool-service files: thread the caller’s session into those helpers, following #35934’s endpoint-owned session and downstream injection pattern. The shared @with_session decorator already provides that controller boundary. [12][13]
For the eventual dependency removal, models/engine.py still constructs Flask-SQLAlchemy’s SQLAlchemy object. That is separate from converting individual callers. [14][15]
Activity
dosubot commentedon Sep 20, 2025
Hi, @asukaminato0721. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.
Issue Summary
Session(db.engine)to simplify thedbinitialization.Next Steps
Thank you for your understanding and contribution!
asukaminato0721 commentedon Feb 5, 2026
@dosu what is current progress
2 remaining items
dataCenter430 commentedon Apr 8, 2026
Hi, @dosu
are there still remaning tasks for this issue?
what is the next step to complete this?
dosubot commentedon Apr 8, 2026
Yes, there's still significant remaining work. Here's a summary of where things stand and what's next:
Current Status: The migration is a two-stage process — Stage 1 replaces
db.sessionwithSession(db.engine)[1], and Stage 2 further optimizes tosessionmaker().begin()which handles commit/rollback automatically [2]. Good progress has been made recently (~7 PRs merged in the last few weeks), but ~150–200 files still need conversion.What's already done:
flask_sqlalchemy[8] [9]What's remaining:
workflow_service.py,dataset_service.py,message_service.py,annotation_service.py, etc.api/core/app/apps/), agent runner (api/core/agent/base_agent_runner.py), RAG pipeline, tool engineapi/models/model.py— these usedb.session.scalar()/db.session.get()in properties, making conversion tricky [13]flask_sqlalchemyfrom dependencies and replace thePaginationimport inapp_service.pyRecommended next steps:
api/models/model.py— this is on the critical path since many other files depend on itAt the current pace, the full migration is estimated at 2–4 months to completion [1]. This is all tracked under the parent epic #23647 [14].
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
dataCenter430 commentedon Apr 8, 2026
@dosu what is the estimate remaining time for this issue.
chore(api): migrate schedule tasks to use SQLAlchemy Session directly
dosubot commentedon Jun 9, 2026
Hi, @asukaminato0721. I'm Dosu, and I'm helping the dify team manage their backlog and am marking this issue as stale.
Recap
Session(db.engine), as part of the broader effort to removeflask_sqlalchemy.db.session.Next Steps
Thanks for your understanding and contribution.
asukaminato0721 commentedon Nov 4, 2026
@dosu any remaining files?
dosubot commentedon Nov 4, 2026
Yes. As of the November 4 checkout, these files still have direct
db.sessionusage beyond cleanup. Paths are relative toapi/; this is a verified shortlist, not an exhaustive backlog:core/agent/base_agent_runner.pycore/app/apps/agent_app/app_runner.pycore/provider_manager.pycore/rag/embedding/cached_embedding.pyservices/tools/api_tools_manage_service.pydb.session()into provider construction. [5]services/tools/tools_transform_service.pyservices/workflow_run_service.pydb.session()into execution-trace assembly. [8]models/workflow.py_resolve_workflow_app_tenant_id()queries through the global session. [9]tasks/initialize_created_app_rbac_access_task.pydb.session(). [10] [11]I’d start with the two tool-service files: thread the caller’s session into those helpers, following #35934’s endpoint-owned session and downstream injection pattern. The shared
@with_sessiondecorator already provides that controller boundary. [12] [13]For the eventual dependency removal,
models/engine.pystill constructs Flask-SQLAlchemy’sSQLAlchemyobject. That is separate from converting individual callers. [14] [15]To reply, just mention @dosu.
Docs are dead. Just use Dosu.