Skip to content

fix: normalize json_schema from string to dict in VariableEntity - #36777

Merged
crazywoola merged 1 commit into
langgenius:mainfrom
EvanYao826:fix/json-schema-string-normalize
Jun 3, 2026
Merged

crazywoola merged 1 commit into
langgenius:mainfrom
EvanYao826:fix/json-schema-string-normalize

Conversation

@EvanYao826

@EvanYao826 EvanYao826 commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #36766
close #36866
close #36895

When workflow graph data is loaded from the database, the json_schema field of JSON object variables may be stored as a JSON string rather than a native dict. VariableEntity.json_schema expects dict | None, causing a Pydantic ValidationError:

1 validation error for VariableEntity
json_schema
  Input should be a valid dictionary [type=dict_type, input_value='{...}', input_type=str]

Changes

  • api/core/app/app_config/workflow_ui_based_app/variables/manager.py: Added _normalize_json_schema() helper that deserializes a JSON string to a dict before passing to model_validate.
  • api/tests/.../test_workflow_ui_based_app_manager.py: Added regression test test_convert_normalizes_json_schema_string_to_dict.

Root Cause

Database JSON columns may serialize nested dicts as strings depending on the ORM/driver path. When loading an existing workflow with a json_object variable whose json_schema was stored as a string, the VariableEntity model rejects it.

Test Plan

  • Unit test passes: pytest api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py -v
  • No regressions in existing variable conversion tests

From Hermes Agent

When workflow graph data is loaded from the database, the json_schema
field of JSON object variables may be stored as a JSON string rather
than a native dict. VariableEntity.json_schema expects dict | None,
causing a Pydantic ValidationError.

Add a _normalize_json_schema helper that deserializes the string before
passing to model_validate, with a regression test.

Fixes langgenius#36766
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-05-28 08:33:03.678747182 +0000
+++ /tmp/pyrefly_pr.txt	2026-05-28 08:32:50.306689067 +0000
@@ -2738,10 +2738,18 @@
    --> tests/unit_tests/core/app/app_config/test_base_app_config_manager.py:156:69
 ERROR Argument `Literal['CHAT']` is not assignable to parameter `app_mode` with type `AppMode` in function `core.app.app_config.base_app_config_manager.BaseAppConfigManager.convert_features` [bad-argument-type]
    --> tests/unit_tests/core/app/app_config/test_base_app_config_manager.py:178:71
+ERROR Cannot index into `VariableEntity` [bad-index]
+  --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:97:16
+ERROR Cannot index into `VariableEntity` [bad-index]
+   --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:118:16
+ERROR Cannot index into `VariableEntity` [bad-index]
+   --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:137:16
+ERROR Cannot index into `VariableEntity` [bad-index]
+   --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:156:16
 ERROR Cannot index into `RagPipelineVariableEntity` [bad-index]
-   --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:141:16
+   --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:222:16
 ERROR Cannot index into `RagPipelineVariableEntity` [bad-index]
-   --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:166:16
+   --> tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py:247:16
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `core.app.apps.advanced_chat.app_config_manager.AdvancedChatAppConfigManager.get_app_config` [bad-argument-type]
   --> tests/unit_tests/core/app/apps/advanced_chat/test_app_config_manager.py:23:70
 ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `core.app.apps.advanced_chat.app_config_manager.AdvancedChatAppConfigManager.get_app_config` [bad-argument-type]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 45.74% 45.73% -0.01%
Strict coverage 45.27% 45.26% -0.01%
Typed symbols 24,619 24,619 0
Untyped symbols 29,508 29,520 +12
Modules 2758 2758 0

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 3, 2026
@crazywoola
crazywoola enabled auto-merge June 3, 2026 04:33
@crazywoola
crazywoola added this pull request to the merge queue Jun 3, 2026
Merged via the queue into langgenius:main with commit 5a0ad4e Jun 3, 2026
31 checks passed
xhdnoah pushed a commit to xhdnoah/dify that referenced this pull request Oct 30, 2026
wylswz pushed a commit that referenced this pull request Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON type input var raise Intenal server error

2 participants