tool invoke error: Instance Account at 0x7f094a2ed7c0 is not bound toa Session; attribute refresh operation cannot proceed #16519

Closed
opened 2026-02-21 19:26:27 -05:00 by yindo · 2 comments
Owner

Originally created by @xiyanluo on GitHub (Aug 28, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.8.0

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Publish the workflow as a tool, and then use an agent to execute the error message. There is no problem with independent workflow execution。
I have searched for other posts with similar issues, but they only mentioned the problem with the account object. How can I make the necessary changes? Can't this variable type be modified in the workflow?

response
f"getDouYinvideo": "tool invoke error: Instance <Account at 0x7f094a2ed7c0> is not bound toa Session; attribute refresh operation cannot proceed (Background on this error at:https://sqlalche.me/e/20/bhk3)"}

✔️ Expected Behavior

Call the tool normally by the agent

Actual Behavior

No response

Originally created by @xiyanluo on GitHub (Aug 28, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.8.0 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Publish the workflow as a tool, and then use an agent to execute the error message. There is no problem with independent workflow execution。 I have searched for other posts with similar issues, but they only mentioned the problem with the account object. How can I make the necessary changes? Can't this variable type be modified in the workflow? response f"getDouYinvideo": "tool invoke error: Instance <Account at 0x7f094a2ed7c0> is not bound toa Session; attribute refresh operation cannot proceed (Background on this error at:https://sqlalche.me/e/20/bhk3)"} ### ✔️ Expected Behavior Call the tool normally by the agent ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 19:26:27 -05:00
yindo closed this issue 2026-02-21 19:26:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 28, 2025):

This error happens because an SQLAlchemy ORM object (like Account) is being accessed outside of an active session, which often occurs when passing ORM objects between workflow/tool boundaries. In Dify, parameters passed to tools should always be primitive types (like IDs, strings, or dicts), not ORM objects. The recommended pattern is to pass the Account ID (or other primitive data) and then re-fetch the Account object from the database within the tool or workflow step that needs it. This avoids session binding errors and fits Dify’s best practices for modular workflows and tools.

Recent Dify versions have improved session management to address these issues. If you’re still seeing this error in 1.8.0, try restarting your Docker container to reset session state for previously created tools (source). For a permanent fix, upgrade to the latest Dify version, as this bug has been addressed in recent releases (source, source).

The reason you don’t see this error in independent workflow execution is that the session context is preserved, but when invoked as a tool by an agent, the session may not be active, exposing the bug.

To fix your workflow/tool: refactor any step that passes an Account object (or any ORM object) to instead pass its ID, and always fetch ORM objects from the database within the session scope where you need them (code reference). This will prevent detached instance errors and make your workflow/tool robust to session boundaries.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 28, 2025): <!-- Answer --> This error happens because an SQLAlchemy ORM object (like Account) is being accessed outside of an active session, which often occurs when passing ORM objects between workflow/tool boundaries. In Dify, parameters passed to tools should always be primitive types (like IDs, strings, or dicts), not ORM objects. The recommended pattern is to pass the Account ID (or other primitive data) and then re-fetch the Account object from the database within the tool or workflow step that needs it. This avoids session binding errors and fits Dify’s best practices for modular workflows and tools. Recent Dify versions have improved session management to address these issues. If you’re still seeing this error in 1.8.0, try restarting your Docker container to reset session state for previously created tools ([source](https://github.com/langgenius/dify/issues/24598)). For a permanent fix, upgrade to the latest Dify version, as this bug has been addressed in recent releases ([source](https://github.com/langgenius/dify/issues/20820), [source](https://github.com/langgenius/dify/issues/20825)). The reason you don’t see this error in independent workflow execution is that the session context is preserved, but when invoked as a tool by an agent, the session may not be active, exposing the bug. To fix your workflow/tool: refactor any step that passes an Account object (or any ORM object) to instead pass its ID, and always fetch ORM objects from the database within the session scope where you need them ([code reference](https://github.com/langgenius/dify/blob/5c01dd97e8cd7070751d31a160311ebb651dbfe3/api/core/workflow/nodes/tool/tool_node.py)). This will prevent detached instance errors and make your workflow/tool robust to session boundaries. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/e5b21c0a-005e-47cf-8573-07ea54d081f1?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/e5b21c0a-005e-47cf-8573-07ea54d081f1?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/e5b21c0a-005e-47cf-8573-07ea54d081f1?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/e5b21c0a-005e-47cf-8573-07ea54d081f1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e5b21c0a-005e-47cf-8573-07ea54d081f1?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/e5b21c0a-005e-47cf-8573-07ea54d081f1?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e5b21c0a-005e-47cf-8573-07ea54d081f1?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/24703)
Author
Owner

@azooly commented on GitHub (Sep 1, 2025):

How can this problem be solved now?

@azooly commented on GitHub (Sep 1, 2025): How can this problem be solved now?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#16519