Tools in Workflows Executed from API: AnonymousUserMixin Error #14224

Closed
opened 2026-02-21 19:16:10 -05:00 by yindo · 4 comments
Owner

Originally created by @jmoratat on GitHub (May 27, 2025).

Originally assigned to: @laipz8200 on GitHub.

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

1.4.0

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Executing any Workflow from API, when internally invokes a Tool (Workflow as Tool)

✔️ Expected Behavior

Executes OK the workflow

Actual Behavior

2025-05-27 10:04:58,759 ERROR [graph_engine.py:586] 55046f765e Unknown Error when generating in parallel
Traceback (most recent call last):
  File "/app/api/core/workflow/graph_engine/graph_engine.py", line 563, in _run_parallel_node
    for item in generator:
                ^^^^^^^^^
  File "/app/api/core/workflow/graph_engine/graph_engine.py", line 317, in _run
    raise e
  File "/app/api/core/workflow/graph_engine/graph_engine.py", line 288, in _run
    for item in generator:
                ^^^^^^^^^
  File "/app/api/core/workflow/graph_engine/graph_engine.py", line 845, in _run_node
    raise e
  File "/app/api/core/workflow/graph_engine/graph_engine.py", line 647, in _run_node
    for item in generator:
                ^^^^^^^^^
  File "/app/api/core/workflow/nodes/base/node.py", line 84, in run
    yield from result
  File "/app/api/core/workflow/nodes/tool/tool_node.py", line 122, in _run
    yield from self._transform_message(message_stream, tool_info, parameters_for_log)
  File "/app/api/core/workflow/nodes/tool/tool_node.py", line 208, in _transform_message
    for message in message_stream:
                   ^^^^^^^^^^^^^^
  File "/app/api/core/tools/utils/message_transformer.py", line 25, in transform_tool_invoke_messages
    for message in messages:
                   ^^^^^^^^
  File "/app/api/core/callback_handler/workflow_tool_callback_handler.py", line 21, in on_tool_execution
    for tool_output in tool_outputs:
                       ^^^^^^^^^^^^
  File "/app/api/core/tools/workflow_as_tool/tool.py", line 89, in _invoke
    result = generator.generate(
             ^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/app/apps/workflow/app_generator.py", line 113, in generate
    user_id=user.id if isinstance(user, Account) else user.session_id,
                                                      ^^^^^^^^^^^^^^^
AttributeError: 'AnonymousUserMixin' object has no attribute 'session_id'

The code line:

`user_id=user.id if isinstance(user, Account) else user.session_id,`

The problem is that 'user' is empty (so there is no 'session_id' or 'id').
Trying to fix it including a "anonymous" text in that 'else', fails a few lines above obtaining the current_tenant_id from user.

In API calls, the user_id is a String that invoker can pass "any string" and could not match with any User database Id (in my case is the name of the invoker platform).

Originally created by @jmoratat on GitHub (May 27, 2025). Originally assigned to: @laipz8200 on GitHub. ### Self Checks - [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 (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.4.0 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Executing any Workflow from API, when internally invokes a Tool (Workflow as Tool) ### ✔️ Expected Behavior Executes OK the workflow ### ❌ Actual Behavior ``` 2025-05-27 10:04:58,759 ERROR [graph_engine.py:586] 55046f765e Unknown Error when generating in parallel Traceback (most recent call last): File "/app/api/core/workflow/graph_engine/graph_engine.py", line 563, in _run_parallel_node for item in generator: ^^^^^^^^^ File "/app/api/core/workflow/graph_engine/graph_engine.py", line 317, in _run raise e File "/app/api/core/workflow/graph_engine/graph_engine.py", line 288, in _run for item in generator: ^^^^^^^^^ File "/app/api/core/workflow/graph_engine/graph_engine.py", line 845, in _run_node raise e File "/app/api/core/workflow/graph_engine/graph_engine.py", line 647, in _run_node for item in generator: ^^^^^^^^^ File "/app/api/core/workflow/nodes/base/node.py", line 84, in run yield from result File "/app/api/core/workflow/nodes/tool/tool_node.py", line 122, in _run yield from self._transform_message(message_stream, tool_info, parameters_for_log) File "/app/api/core/workflow/nodes/tool/tool_node.py", line 208, in _transform_message for message in message_stream: ^^^^^^^^^^^^^^ File "/app/api/core/tools/utils/message_transformer.py", line 25, in transform_tool_invoke_messages for message in messages: ^^^^^^^^ File "/app/api/core/callback_handler/workflow_tool_callback_handler.py", line 21, in on_tool_execution for tool_output in tool_outputs: ^^^^^^^^^^^^ File "/app/api/core/tools/workflow_as_tool/tool.py", line 89, in _invoke result = generator.generate( ^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/workflow/app_generator.py", line 113, in generate user_id=user.id if isinstance(user, Account) else user.session_id, ^^^^^^^^^^^^^^^ AttributeError: 'AnonymousUserMixin' object has no attribute 'session_id' ``` The code line: ``` `user_id=user.id if isinstance(user, Account) else user.session_id,` ``` The problem is that 'user' is empty (so there is no 'session_id' or 'id'). Trying to fix it including a "anonymous" text in that 'else', fails a few lines above obtaining the current_tenant_id from user. In API calls, the user_id is a String that invoker can pass "any string" and could not match with any User database Id (in my case is the name of the invoker platform).
yindo added the 🐞 bug label 2026-02-21 19:16:10 -05:00
yindo closed this issue 2026-02-21 19:16:10 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (May 27, 2025):

Hi @jmoratat! I'm Dosu and I’m helping the dify team.

The error you're encountering (AttributeError: 'AnonymousUserMixin' object has no attribute 'session_id') occurs because, during workflow execution via the API, the code attempts to access user.session_id on an object that is actually an instance of AnonymousUserMixin. This class, provided by Flask-Login, is used to represent users who are not authenticated and does not have a session_id attribute reference.

In Dify, authenticated users are typically represented by either the Account or EndUser classes. The EndUser class does have a session_id attribute reference, but AnonymousUserMixin does not. The error suggests that, when invoking a tool within a workflow via the API, the user context is not being set correctly, resulting in an anonymous user being passed where an authenticated user (with a session_id) is expected.

Summary of findings:

  • The error is triggered when the workflow code tries to access user.session_id but receives an AnonymousUserMixin instance instead.
  • This likely means the API call is not providing or resolving a valid user context for the workflow/tool execution.
  • No relevant documentation or existing issues were found regarding this specific error or handling anonymous users in this context.

Potential next steps:

  • Review how the user context is established when executing workflows via the API. Ensure that a valid EndUser or Account object is being passed through the workflow and tool invocation stack, not an anonymous user.
  • If anonymous access is expected, you may need to update the code to handle this case gracefully (e.g., by generating a temporary session or skipping user-specific logic).
  • Specifically, check the logic around where the user object is set or passed into the workflow execution, and ensure it is never an AnonymousUserMixin when a session_id is required.

If you need more detailed guidance on where to look in the codebase or how to patch this, let me know!

To reply, just mention my name @dosu.


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

@dosubot[bot] commented on GitHub (May 27, 2025): <!-- Greeting --> Hi @jmoratat! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> The error you're encountering (`AttributeError: 'AnonymousUserMixin' object has no attribute 'session_id'`) occurs because, during workflow execution via the API, the code attempts to access `user.session_id` on an object that is actually an instance of `AnonymousUserMixin`. This class, provided by Flask-Login, is used to represent users who are not authenticated and does not have a `session_id` attribute [reference](https://github.com/langgenius/dify/blob/main/api/controllers/console/auth/login.py). In Dify, authenticated users are typically represented by either the `Account` or `EndUser` classes. The `EndUser` class does have a `session_id` attribute [reference](https://github.com/langgenius/dify/blob/main/api/models/model.py), but `AnonymousUserMixin` does not. The error suggests that, when invoking a tool within a workflow via the API, the user context is not being set correctly, resulting in an anonymous user being passed where an authenticated user (with a `session_id`) is expected. **Summary of findings:** - The error is triggered when the workflow code tries to access `user.session_id` but receives an `AnonymousUserMixin` instance instead. - This likely means the API call is not providing or resolving a valid user context for the workflow/tool execution. - No relevant documentation or existing issues were found regarding this specific error or handling anonymous users in this context. **Potential next steps:** - Review how the user context is established when executing workflows via the API. Ensure that a valid `EndUser` or `Account` object is being passed through the workflow and tool invocation stack, not an anonymous user. - If anonymous access is expected, you may need to update the code to handle this case gracefully (e.g., by generating a temporary session or skipping user-specific logic). - Specifically, check the logic around where the `user` object is set or passed into the workflow execution, and ensure it is never an `AnonymousUserMixin` when a `session_id` is required. If you need more detailed guidance on where to look in the codebase or how to patch this, let me know! <!-- Dosu Comment Footer --> *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/56f4fcd0-6c33-493c-8e47-a227e3fa5c51?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/56f4fcd0-6c33-493c-8e47-a227e3fa5c51?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/56f4fcd0-6c33-493c-8e47-a227e3fa5c51?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/56f4fcd0-6c33-493c-8e47-a227e3fa5c51?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/56f4fcd0-6c33-493c-8e47-a227e3fa5c51?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/56f4fcd0-6c33-493c-8e47-a227e3fa5c51?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/56f4fcd0-6c33-493c-8e47-a227e3fa5c51?feedback_type=other)</sup>&nbsp;&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/20309)
Author
Owner

@jmoratat commented on GitHub (May 27, 2025):

@laipz8200 it's not solved. Upgrading with the https://github.com/langgenius/dify/pull/20240 its still failing with the same error.

@jmoratat commented on GitHub (May 27, 2025): @laipz8200 it's not solved. Upgrading with the https://github.com/langgenius/dify/pull/20240 its still failing with the same error.
Author
Owner

@laipz8200 commented on GitHub (May 27, 2025):

Hi @jmoratat. We can't reproduce this error on the 1.4.1 version. Could you please provide us with a minimal DSL file that can reproduce this issue?

@laipz8200 commented on GitHub (May 27, 2025): Hi @jmoratat. We can't reproduce this error on the 1.4.1 version. Could you please provide us with a minimal DSL file that can reproduce this issue?
Author
Owner

@jmoratat commented on GitHub (May 27, 2025):

Hi @jmoratat. We can't reproduce this error on the 1.4.1 version. Could you please provide us with a minimal DSL file that can reproduce this issue?

Hi @laipz8200 ! Has been solved with #20321 !! thank u! (The problem was the parallel nodes :)

@jmoratat commented on GitHub (May 27, 2025): > Hi [@jmoratat](https://github.com/jmoratat). We can't reproduce this error on the 1.4.1 version. Could you please provide us with a minimal DSL file that can reproduce this issue? Hi @laipz8200 ! Has been solved with #20321 !! thank u! (The problem was the parallel nodes :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14224