rewrite property to accept session: Session as parameter
Yes: 3 files still contain implicit database access in the current checkout (
34c9438623), including properties that create their own sessions rather than usedb.session.
File Remaining entry points What to do api/models/workflow.py_resolve_workflow_app_tenant_idStill calls db.session.scalar(...). Thread the caller's session through the draft-variable decoding chain. Already claimed by @keith991001 in the latest comment. [1]api/models/workflow.pyWorkflowAppLog.workflow_runProperty constructs a session factory and queries through a repository. Replace implicit session ownership with an explicit-session lookup, auditing callers and response serialization. [2] api/models/model.pyMessage.workflow_runSame session-factory/repository pattern. Convert alongside the log accessor or as a separate focused slice. [3] api/models/provider.pyProvider.credential,ProviderModel.credentialBoth are cached_propertyaccessors that open sessions throughsession_factory.create_session(). Convert to explicit-session methods and audit dependentcredential_name/encrypted_configproperties, including the provider'stoken_is_set/is_enabledchain. Decide how to preserve caching semantics. [4] [5]The previous
AppModelConfig.annotation_reply_dictitem is gone:AppModelConfig.to_dict()now requires an explicitannotation_replyvalue, with no implicit fallback. [6]So the additional cleanup candidates beyond Keith's claimed resolver are four accessors across these three files. Their session creation was missed by the earlier
db.session-only inventory.To reply, just mention @dosu.
Docs are dead. Just use Dosu.
Originally posted by @dosubot in #40372
Hi maintainers — I'd like to take a focused, non-overlapping slice of #45166 if it is available for assignment (@GYJ99).
Scope: WorkflowAppLog.workflow_run (api/models/workflow.py) and Message.workflow_run (api/models/model.py). Both properties currently construct their own sessionmaker(bind=db.engine) and workflow-run repository. I would audit production callers and repository/archive behavior first, then make the lookup accept a caller-owned Session without changing the existing lookup semantics. I will cover the no-run-id/missing-run cases and any affected response serialization with focused SQLite-backed tests, followed by Ruff and type-checking.
I will not touch @keith991001's already-claimed _resolve_workflow_app_tenant_id chain or the separate provider credential accessors. This is source-level triage and a test plan, not a claim that I have run the Dify tests or accessed a local checkout. I used ChatGPT to help scope the code paths and will disclose assistance in a resulting PR.
Would you be comfortable assigning this two-accessor slice to @GYJ99? Thanks!
Update on my proposed two-accessor slice of #45166: I rechecked current main and confirmed that #45168 was merged on November 5 (fc53a9fed358), removing both Message.workflow_run and WorkflowAppLog.workflow_run after verifying they had no production callers. That fully supersedes the scope I offered, so I will not open a duplicate PR. The separate _resolve_workflow_app_tenant_id path is already being addressed in #43112 by @keith991001. Thanks to @xiaoyuCR7 for the completed cleanup. My source-level check is not a claim that I ran the Dify test suite; the merged PR has its own recorded validation. Maintainers may unassign @GYJ99 from this now-completed slice if appropriate.
@dosu any remaining files?
Yes, one file remains from this cleanup scope on the November 10 checkout (172dc9b477):
api/models/workflow.py:_resolve_workflow_app_tenant_idstill callsdb.session.scalar(...). Thread a caller-ownedSessionthrough the draft-variable decoding chain. This is already covered by @keith991001’s open PR #43112, so no duplicate slice is needed. [1]
PR #45168 completed both the workflow-run accessor removals and the provider credential cleanup. Provider.credential is now a lazy="raise" relationship requiring caller-side loading, and the ProviderModel credential accessors are gone. provider.py therefore no longer needs the previously suggested conversion. [2] [3]
Nothing additional to claim from the previous three-file list.
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
@dosu
but there are 300+ right?
My previous “one file remains” answer was limited to implicit database access in api/models/, not all properties or all session usage across the repository. I should have made that boundary clearer.
There are two different inventories:
- All
@propertydeclarations: not all require conversion. For example,AppModelConfig.model_dictandsuggested_questions_listonly decode stored JSON; they need no database session. [1] - Implicit database access: the model-level cleanup is separate from the broader controller/service/core session-injection work tracked in #37403. The latter is not completed by this issue. [2]
Within the model-level scan, _resolve_workflow_app_tenant_id still uses the global session. That supports the narrow remaining item, not a repository-wide completion claim. [3]
I couldn’t load the attached image, so I can’t confirm what the 300+ counts. Could you paste the search expression and included directory? That will let me distinguish remaining conversion candidates from unrelated matches.
You can use @dosu save this to preserve the scope correction.
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
Hello, and thank you for labelling this as a good first issue and for welcoming new contributors.
I'm interested in working on it. I build full-stack apps in TypeScript, so the codebase should be comfortable for me. Could you please assign it to me? I'll post a short plan first.
Hi - I'd like to take a slice of this cleanup if any model-level work remains. From the thread: #45168 (merged Nov 5) removed the Message.workflow_run / WorkflowAppLog.workflow_run accessors and converted the provider credential accessors to explicit loading, and _resolve_workflow_app_tenant_id is covered by @keith991001's #43112, so I don't want to duplicate either. If there's a remaining implicit-session accessor in api/models/ I'm happy to take it; otherwise I'd gladly pick up a focused slice of the broader session-injection work in #37403, threading a caller-owned Session through one controller/service chain with tests. I work with SQLAlchemy + FastAPI in production daily, including this exact kind of session-ownership-at-the-boundary refactor in a multi-tenant billing codebase. Could a maintainer point me at a slice and assign it? Thanks!