dify - 💡(How to fix) Fix fetch memory of LLM node may cause out of flask context [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

2026-05-16 13:10:20,322 ERROR [graph.py:163] Failed to create node instance for node_id 1778936649563 Traceback (most recent call last): File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/graphon/graph/graph.py", line 161, in _create_node_instances node_instance = node_factory.create_node(node_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 444, in create_node node_init_kwargs = node_init_kwargs_factories.get(node_type, lambda: {})() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 399, in <lambda> BuiltinNodeTypes.LLM: lambda: self._build_llm_compatible_node_init_kwargs( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 486, in _build_llm_compatible_node_init_kwargs "memory": self._build_memory_for_llm_node( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 561, in _build_memory_for_llm_node return fetch_memory( ^^^^^^^^^^^^^ File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 235, in fetch_memory with Session(db.engine, expire_on_commit=False) as session: ^^^^^^^^^ File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/flask_sqlalchemy/extension.py", line 709, in engine return self.engines[None] ^^^^^^^^^^^^ File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/flask_sqlalchemy/extension.py", line 687, in engines app = current_app._get_current_object() # type: ignore[attr-defined] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/werkzeug/local.py", line 519, in _get_current_object raise RuntimeError(unbound_message) from None RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed the current application. To solve this, set up an application context with app.app_context(). See the documentation for more information.

Fix Action

Fixed

Code Example

2026-05-16 13:10:20,322 ERROR [graph.py:163]  Failed to create node instance for node_id 1778936649563
Traceback (most recent call last):
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/graphon/graph/graph.py", line 161, in _create_node_instances
    node_instance = node_factory.create_node(node_config)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 444, in create_node
    node_init_kwargs = node_init_kwargs_factories.get(node_type, lambda: {})()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 399, in <lambda>
    BuiltinNodeTypes.LLM: lambda: self._build_llm_compatible_node_init_kwargs(
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 486, in _build_llm_compatible_node_init_kwargs
    "memory": self._build_memory_for_llm_node(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 561, in _build_memory_for_llm_node
    return fetch_memory(
           ^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 235, in fetch_memory
    with Session(db.engine, expire_on_commit=False) as session:
                 ^^^^^^^^^
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/flask_sqlalchemy/extension.py", line 709, in engine
    return self.engines[None]
           ^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/flask_sqlalchemy/extension.py", line 687, in engines
    app = current_app._get_current_object()  # type: ignore[attr-defined]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/werkzeug/local.py", line 519, in _get_current_object
    raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.
RAW_BUFFERClick to expand / collapse

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.4.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

error log:

2026-05-16 13:10:20,322 ERROR [graph.py:163]  Failed to create node instance for node_id 1778936649563
Traceback (most recent call last):
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/graphon/graph/graph.py", line 161, in _create_node_instances
    node_instance = node_factory.create_node(node_config)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 444, in create_node
    node_init_kwargs = node_init_kwargs_factories.get(node_type, lambda: {})()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 399, in <lambda>
    BuiltinNodeTypes.LLM: lambda: self._build_llm_compatible_node_init_kwargs(
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 486, in _build_llm_compatible_node_init_kwargs
    "memory": self._build_memory_for_llm_node(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 561, in _build_memory_for_llm_node
    return fetch_memory(
           ^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/core/workflow/node_factory.py", line 235, in fetch_memory
    with Session(db.engine, expire_on_commit=False) as session:
                 ^^^^^^^^^
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/flask_sqlalchemy/extension.py", line 709, in engine
    return self.engines[None]
           ^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/flask_sqlalchemy/extension.py", line 687, in engines
    app = current_app._get_current_object()  # type: ignore[attr-defined]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hejl/projects/dify/api/.venv/lib/python3.12/site-packages/werkzeug/local.py", line 519, in _get_current_object
    raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.
<img width="1384" height="926" alt="Image" src="https://github.com/user-attachments/assets/1ce7fa7d-2a08-4897-ae9c-4309e1ec1ffc" />

minimal reproduce DSL: aa (1).yml

a first LLM node with memory open, and then connect a iteration node with parallel mode and contains another LLM node can raise this exception.

✔️ Expected Behavior

not raise exception

❌ Actual Behavior

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

dify - 💡(How to fix) Fix fetch memory of LLM node may cause out of flask context [1 pull requests]