DetachedInstanceError in Workflow Response Generation #11814
Description
Self Checks
- 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 (我已阅读并同意 Language Policy).
- [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- Please do not modify this template :) and fill in all the required fields.
Dify version
0.14.1
Cloud or Self Hosted
Cloud, Self Hosted (Docker)
Steps to reproduce
✔️ Expected Behavior
No response
❌ Actual Behavior
api-1 | [2024-12-18 18:17:13 +0000] [24] [ERROR] Error handling request
api-1 | Traceback (most recent call last):
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/gunicorn/workers/base_async.py", line 114, in handle_request
api-1 | for item in respiter:
api-1 | ^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wsgi.py", line 256, in next
api-1 | return self._next()
api-1 | ^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded
api-1 | for item in iterable:
api-1 | ^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/flask/helpers.py", line 125, in generator
api-1 | yield from gen
api-1 | File "/app/api/libs/helper.py", line 191, in generate
api-1 | yield from response
api-1 | File "/app/api/core/app/features/rate_limiting/rate_limit.py", line 112, in next
api-1 | return next(self.generator)
api-1 | ^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/core/app/apps/base_app_generate_response_converter.py", line 27, in _generate_full_response
api-1 | for chunk in cls.convert_stream_full_response(response):
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/core/app/apps/workflow/generate_response_converter.py", line 46, in convert_stream_full_response
api-1 | for chunk in stream_response:
api-1 | ^^^^^^^^^^^^^^^
api-1 | File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 167, in _to_stream_response
api-1 | for stream_response in generator:
api-1 | ^^^^^^^^^
api-1 | File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 196, in _wrapper_process_stream_response
api-1 | for response in self._process_stream_response(tts_publisher=tts_publisher, trace_manager=trace_manager):
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 397, in _process_stream_response
api-1 | yield self._workflow_finish_to_stream_response(
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/core/app/task_pipeline/workflow_cycle_manage.py", line 461, in workflow_finish_to_stream_response
api-1 | if workflow_run.created_by_role == CreatedByRole.ACCOUNT.value:
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py", line 566, in get
api-1 | return self.impl.get(state, dict) # type: ignore[no-any-return]
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py", line 1086, in get
api-1 | value = self._fire_loader_callables(state, key, passive)
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py", line 1116, in _fire_loader_callables
api-1 | return state._load_expired(state, passive)
api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state.py", line 803, in _load_expired
api-1 | self.manager.expired_attribute_loader(self, toload, passive)
api-1 | File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/loading.py", line 1603, in load_scalar_attributes
api-1 | raise orm_exc.DetachedInstanceError(
api-1 | sqlalchemy.orm.exc.DetachedInstanceError: Instance <WorkflowRun at 0x7fa2cd4e8f80> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)