When clear number variable, throw error: Run failed: <SegmentType.INTEGER: 'integer'> #20184

Closed
opened 2026-02-21 20:06:12 -05:00 by yindo · 2 comments
Owner

Originally created by @CrabSAMA on GitHub (Nov 6, 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.9.2

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Chatflow DSL:
test chatflow.yml

Chatflow:
Image

  1. new a chatflow
  2. add one conversation variables of number type
  3. add variable operation node, to clear this variable
  4. run this chatflow, will see the error

✔️ Expected Behavior

Run successful, no error.

Actual Behavior

Image

Error stack log:

2025-11-07 03:11:32,645 INFO [_internal.py:97] 2caa732e0b 127.0.0.1 - - [07/Nov/2025 03:11:32] "POST /console/api/apps/9a40cf2f-8883-4bde-845e-068dd9ffa44a/advanced-chat/workflows/draft/run HTTP/1.1" 200 -
2025-11-07 03:11:32,778 ERROR [node.py:162] ee1eebcc8d Node 1762429123638 failed to run
Traceback (most recent call last):
  File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/nodes/base/node.py", line 144, in run
    result = self._run()
             ^^^^^^^^^^^
  File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/nodes/variable_assigner/v2/node.py", line 187, in _run
    updated_value = self._handle_item(
                    ^^^^^^^^^^^^^^^^^^
  File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/nodes/variable_assigner/v2/node.py", line 252, in _handle_item
    return EMPTY_VALUE_MAPPING[variable.value_type]
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
KeyError: <SegmentType.INTEGER: 'integer'>
2025-11-07 03:11:32,819 ERROR [error_handler.py:101]  Node 1762429123638 failed with ABORT strategy: <SegmentType.INTEGER: 'integer'>
2025-11-07 03:11:32,887 ERROR [workflow_entry.py:111] 9968d60078 Unknown Error when workflow entry running
Traceback (most recent call last):
  File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/workflow_entry.py", line 107, in run
    yield from generator
  File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/graph_engine/graph_engine.py", line 271, in run
    raise self._graph_execution.error
RuntimeError: <SegmentType.INTEGER: 'integer'>
Originally created by @CrabSAMA on GitHub (Nov 6, 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.9.2 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Chatflow DSL: [test chatflow.yml](https://github.com/user-attachments/files/23408054/test.chatflow.yml) Chatflow: ![Image](https://github.com/user-attachments/assets/1382cc67-016b-44a8-8e5b-6a7ca1c243a1) 1. new a chatflow 2. add one conversation variables of `number` type 3. add variable operation node, to clear this variable 4. run this chatflow, will see the error ### ✔️ Expected Behavior Run successful, no error. ### ❌ Actual Behavior ![Image](https://github.com/user-attachments/assets/05655d75-d923-41ba-bc16-5264c00e8bb3) Error stack log: ```bash 2025-11-07 03:11:32,645 INFO [_internal.py:97] 2caa732e0b 127.0.0.1 - - [07/Nov/2025 03:11:32] "POST /console/api/apps/9a40cf2f-8883-4bde-845e-068dd9ffa44a/advanced-chat/workflows/draft/run HTTP/1.1" 200 - 2025-11-07 03:11:32,778 ERROR [node.py:162] ee1eebcc8d Node 1762429123638 failed to run Traceback (most recent call last): File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/nodes/base/node.py", line 144, in run result = self._run() ^^^^^^^^^^^ File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/nodes/variable_assigner/v2/node.py", line 187, in _run updated_value = self._handle_item( ^^^^^^^^^^^^^^^^^^ File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/nodes/variable_assigner/v2/node.py", line 252, in _handle_item return EMPTY_VALUE_MAPPING[variable.value_type] ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^ KeyError: <SegmentType.INTEGER: 'integer'> 2025-11-07 03:11:32,819 ERROR [error_handler.py:101] Node 1762429123638 failed with ABORT strategy: <SegmentType.INTEGER: 'integer'> 2025-11-07 03:11:32,887 ERROR [workflow_entry.py:111] 9968d60078 Unknown Error when workflow entry running Traceback (most recent call last): File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/workflow_entry.py", line 107, in run yield from generator File "/Users/crab.huang/Project/opensource/dify/api/core/workflow/graph_engine/graph_engine.py", line 271, in run raise self._graph_execution.error RuntimeError: <SegmentType.INTEGER: 'integer'> ```
yindo added the 🐞 bug label 2026-02-21 20:06:12 -05:00
yindo closed this issue 2026-02-21 20:06:12 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 6, 2025):

This error happens because the variable assigner node's EMPTY_VALUE_MAPPING does not include an entry for SegmentType.INTEGER, so when you clear an integer variable, it throws a KeyError. To fix this, add the following lines to api/core/workflow/nodes/variable_assigner/v2/constants.py:

from core.variables.types import SegmentType

EMPTY_VALUE_MAPPING = {
    SegmentType.STRING: "",
    SegmentType.NUMBER: 0,
    SegmentType.INTEGER: 0,   # <-- Add this line
    SegmentType.FLOAT: 0.0,   # <-- And this line if you use float variables
    SegmentType.BOOLEAN: False,
    SegmentType.OBJECT: {},
    SegmentType.ARRAY_ANY: [],
    SegmentType.ARRAY_STRING: [],
    SegmentType.ARRAY_NUMBER: [],
    SegmentType.ARRAY_OBJECT: [],
    SegmentType.ARRAY_BOOLEAN: [],
}

This matches the robust handling in the v1 node, where clearing an integer variable sets it to 0 and a float to 0.0 citation. After making this change, clearing integer (and float) variables should work without error citation.

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 (Nov 6, 2025): <!-- Answer --> This error happens because the variable assigner node's EMPTY_VALUE_MAPPING does not include an entry for `SegmentType.INTEGER`, so when you clear an integer variable, it throws a KeyError. To fix this, add the following lines to `api/core/workflow/nodes/variable_assigner/v2/constants.py`: ```python from core.variables.types import SegmentType EMPTY_VALUE_MAPPING = { SegmentType.STRING: "", SegmentType.NUMBER: 0, SegmentType.INTEGER: 0, # <-- Add this line SegmentType.FLOAT: 0.0, # <-- And this line if you use float variables SegmentType.BOOLEAN: False, SegmentType.OBJECT: {}, SegmentType.ARRAY_ANY: [], SegmentType.ARRAY_STRING: [], SegmentType.ARRAY_NUMBER: [], SegmentType.ARRAY_OBJECT: [], SegmentType.ARRAY_BOOLEAN: [], } ``` This matches the robust handling in the v1 node, where clearing an integer variable sets it to `0` and a float to `0.0` [citation](https://github.com/langgenius/dify/blob/37903722fe3583cd82addb804e57b1dcdd959e4b/api/core/workflow/nodes/variable_assigner/v1/node.py#L97-L166). After making this change, clearing integer (and float) variables should work without error [citation](https://github.com/langgenius/dify/blob/37903722fe3583cd82addb804e57b1dcdd959e4b/api/core/workflow/nodes/variable_assigner/v2/constants.py#L4-L14). <!-- 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/51db2460-e6e5-4bca-81ec-5fe43ede85c8?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/51db2460-e6e5-4bca-81ec-5fe43ede85c8?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/51db2460-e6e5-4bca-81ec-5fe43ede85c8?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/51db2460-e6e5-4bca-81ec-5fe43ede85c8?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/51db2460-e6e5-4bca-81ec-5fe43ede85c8?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/51db2460-e6e5-4bca-81ec-5fe43ede85c8?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/51db2460-e6e5-4bca-81ec-5fe43ede85c8?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/27952)
Author
Owner

@CrabSAMA commented on GitHub (Nov 6, 2025):

After this pr: https://github.com/langgenius/dify/pull/22025
diff: https://github.com/langgenius/dify/pull/22025/files#diff-d2dc8eedc1e4f0db1a85e69c014235dbed53a649dd26fa0d8a76aa1d61698ddd

It enhance NUMBER type to INTEGER and FLOAT, but EMPTY_VALUE_MAPPING miss both new type, considering the issue of code duplication mentioned in TODO, I will provide a PR for repair and refactoring.

PR here: https://github.com/langgenius/dify/pull/27954

@CrabSAMA commented on GitHub (Nov 6, 2025): After this pr: https://github.com/langgenius/dify/pull/22025 diff: https://github.com/langgenius/dify/pull/22025/files#diff-d2dc8eedc1e4f0db1a85e69c014235dbed53a649dd26fa0d8a76aa1d61698ddd It enhance `NUMBER` type to `INTEGER` and `FLOAT`, but `EMPTY_VALUE_MAPPING ` miss both new type, considering the issue of code duplication mentioned in TODO, I will provide a PR for repair and refactoring. PR here: https://github.com/langgenius/dify/pull/27954
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20184