[PR #31404] fix: str object has no attribute get in agent node with disable auto variable #33217

Open
opened 2026-02-21 20:52:53 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/31404

State: open
Merged: No


…variable

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix: 26559
The reason is that the variable contains escape characters, which causes an error when the string returned by variable_pool.convert_template is converted back to JSON.

                try:
                    if not isinstance(agent_input.value, str):
                        parameter_value = json.loads(parameter_value)
                except json.JSONDecodeError:
                    parameter_value = parameter_value

parameter_value will ultimately be a str, not a json. Then tool.get("enabled", False) will throw exception 'str object has no attribute get ' as below.

            if parameter.type == "array[tools]":
                value = cast(list[dict[str, Any]], value)
                value = [tool for tool in value if tool.get("enabled", False)]

Screenshots

Before

set variable:
image

use variable and disable auto:
image

After

image The variable is correctly parsed.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/31404 **State:** open **Merged:** No --- …variable > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary fix: [26559](https://github.com/langgenius/dify/issues/26559) The reason is that the variable contains escape characters, which causes an error when the string returned by variable_pool.convert_template is converted back to JSON. ``` try: if not isinstance(agent_input.value, str): parameter_value = json.loads(parameter_value) except json.JSONDecodeError: parameter_value = parameter_value ``` parameter_value will ultimately be a str, not a json. Then tool.get("enabled", False) will throw exception 'str object has no attribute get ' as below. ``` if parameter.type == "array[tools]": value = cast(list[dict[str, Any]], value) value = [tool for tool in value if tool.get("enabled", False)] ``` ## Screenshots ### Before set variable: <img width="971" height="499" alt="image" src="https://github.com/user-attachments/assets/39745f74-5547-4f4b-9bff-a2345b451d6e" /> use variable and disable auto: <img width="1868" height="890" alt="image" src="https://github.com/user-attachments/assets/e78a2184-6ef8-4a43-884a-0802a6b3bc6c" /> #### After <img width="848" height="717" alt="image" src="https://github.com/user-attachments/assets/4414e85b-1201-4401-b06d-d9ae54a56c2c" /> The variable is correctly parsed. ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33217