Skip to content

rewrite property to accept session: Session as parameter #45166

Open

Description

@asukaminato0721

Yes: 3 files still contain implicit database access in the current checkout (34c9438623), including properties that create their own sessions rather than use db.session.

File Remaining entry points What to do
api/models/workflow.py _resolve_workflow_app_tenant_id Still 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.py WorkflowAppLog.workflow_run Property 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.py Message.workflow_run Same session-factory/repository pattern. Convert alongside the log accessor or as a separate focused slice. [3]
api/models/provider.py Provider.credential, ProviderModel.credential Both are cached_property accessors that open sessions through session_factory.create_session(). Convert to explicit-session methods and audit dependent credential_name / encrypted_config properties, including the provider's token_is_set / is_enabled chain. Decide how to preserve caching semantics. [4] [5]

The previous AppModelConfig.annotation_reply_dict item is gone: AppModelConfig.to_dict() now requires an explicit annotation_reply value, 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.

Leave Feedback Ask Dosu about dify

Originally posted by @dosubot in #40372

Activity

  1. added
    good first issue
    on Oct 30, 2026
  2. GYJ99 commented on Oct 30, 2026

    @GYJ99

    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!

  3. GYJ99 commented on Nov 5, 2026

    @GYJ99

    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.

  4. asukaminato0721 commented on Nov 10, 2026

    @asukaminato0721
    ContributorAuthor

    @dosu any remaining files?

  5. dosubot commented on Nov 10, 2026

    @dosubot

    Yes, one file remains from this cleanup scope on the November 10 checkout (172dc9b477):

    • api/models/workflow.py: _resolve_workflow_app_tenant_id still calls db.session.scalar(...). Thread a caller-owned Session through 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.

    Leave Feedback Learn about dify with Dosu

  6. asukaminato0721 commented on Nov 10, 2026

    @asukaminato0721
    ContributorAuthor

    @dosu

    Image but there are 300+ right?

  7. dosubot commented on Nov 10, 2026

    @dosubot

    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 @property declarations: not all require conversion. For example, AppModelConfig.model_dict and suggested_questions_list only 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 make db.session pass from parameter. #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.

    Leave Feedback Learn about dify with Dosu

  8. Vijay431 commented on Nov 26, 2026

    @Vijay431

    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.

  9. ahmed14527 commented on Nov 26, 2026

    @ahmed14527

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions