Replies: 1 comment 1 reply
-
|
Hi @wangyucha! I'm Dosu and I’m helping the dify team. This error happens because the Account object is being accessed outside of an active SQLAlchemy session—usually when agent-invoked tools or chatflows pass ORM objects across async boundaries or after the session is closed. Direct workflow-to-workflow calls keep objects session-bound, but agent/tool invocation often serializes/deserializes data, so only IDs should be passed and ORM objects must be re-fetched inside a fresh session context. How to fix: from sqlalchemy.orm import Session
with Session(db.engine) as session:
account = session.query(Account).get(account_id)
# use account safely hereIf you must use an ORM object after the session is closed, re-attach it with Recent Dify versions (after v1.8.0) have improved session management for tool invocation, but the best practice is to always re-query by ID within a session. Upgrading to the latest version is recommended for a permanent fix, as session handling in workflow runners and tool services has been refactored (example PR, session fix). Temporary workarounds like expunging objects from the session before returning them exist, but are not recommended for production use. For more details and code examples, see this issue thread. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
When I call the local workflow in the studio's agent and chatflow, this error occurs. However, it doesn't appear when a workflow calls another workflow. How can I resolve this issue?
“tool invoke error: Instance <Account at 0x7677bc952000> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)”
2. Additional context or comments
No response
Beta Was this translation helpful? Give feedback.
All reactions