Skip to content

Node setInputs cannot remove keys: handleNodeDataUpdate shallow-merge keeps deleted fields (e.g. Knowledge Retrieval V2 metadata_filters) #45443

Open

Description

@hyoban

Summary

A node setInputs cannot remove a key from node data. useNodeCrud().setInputs goes through handleNodeDataUpdate, which shallow-merges the new inputs into the existing data ({ ...currentNode.data, ...data }). Any top-level key the caller deleted therefore keeps its old value.

Where

Verified on main at fbc33cae43:

  • web/app/components/workflow/hooks/use-node-data-update.ts:24: currentNode.data = { ...currentNode.data, ...data }
  • web/app/components/workflow/nodes/_base/hooks/use-node-crud.ts:13-21: setInputs forwards the full new inputs as data.
  • Affected caller found by tests: web/app/components/workflow/nodes/knowledge-retrieval-v2/use-config.ts:144-160 (handleMetadataFilterChange). When the last filter value is cleared, it does delete draft.metadata_filters, so the stale metadata_filters survives. handleNodeKindToggle (L162-170) is affected the same way when the last node kind is toggled off.
  • Another caller with the same pattern: web/app/components/workflow/nodes/knowledge-retrieval/hooks/use-knowledge-input-manager.ts:13-17 deletes single_retrieval_config / multiple_retrieval_config when the retrieval mode changes, so the unused config is probably never removed from node data. Not separately verified at runtime.

Steps to reproduce (hook level)

  1. Render a Knowledge Retrieval V2 node whose data has metadata_filters: { tags: ['policy'] }.
  2. Call handleMetadataFilterChange('tags', []) from useConfig.
  3. Read the node from the canvas store.

Expected

metadata_filters is removed (or is {}), so no tag filter is applied.

Actual

The node data still has metadata_filters: { tags: ['policy'] }, and the draft sync persists the stale filter.

Note: on current main, panel.tsx does not appear to wire handleMetadataFilterChange / handleNodeKindToggle into the UI yet. The root cause in handleNodeDataUpdate affects any setInputs caller that removes a top-level key.

Suggested fix

Replace node data instead of merging when a caller passes the full inputs, as useNodeCrud.setInputs does. Alternatively, have callers set keys to undefined and strip them, rather than using delete.

How this was found

This came up during the web test cleanup (#44630). The old web/app/components/workflow/nodes/knowledge-retrieval-v2/__tests__/use-config.spec.ts mocked the node CRUD setter and only asserted the setter payload, so it could not see the merge. With the real canvas, the "clears metadata filter" case failed. That misleading case was removed rather than asserting the buggy behavior. A regression test should be added together with the fix.

Activity

  1. dosubot commented on Nov 3, 2026

    @dosubot

    One constraint for the fix: handleNodeDataUpdateWithSyncDraft also serves partial-update callers. The node panel sends only { title } or { desc }, and retry settings send only { retry_config }, so making the shared updater replace data unconditionally would discard unrelated fields for those callers. [1] [2]

    The existing use-node-data-update.spec.ts explicitly tests merge semantics, including preserving title and earlier edits. That provides a compatibility check alongside the new deletion regression: retain patch behavior for direct callers, and distinguish full-input replacement through setInputs, which currently forwards its payload without any replacement marker. [3] [4]

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

  2. added
    1.18.0
    on Nov 3, 2026
  3. GYJ99 commented on Nov 3, 2026

    @GYJ99

    Hi @hyoban — I'd be happy to take a focused fix for this if nobody is already working on it.

    I checked the current call path: useNodeCrud().setInputs passes a full node-data snapshot into handleNodeDataUpdateWithSyncDraft, but handleNodeDataUpdate shallow-merges it with the previous data, retaining keys intentionally deleted by callers. The shared updater also handles partial patches (e.g. title/description and retry settings), so globally switching it to replacement would be unsafe.

    I'd isolate full-snapshot replacement (or explicit key removal) to the setInputs path while keeping partial updates as merges. The regression plan is to test clearing the final Knowledge Retrieval V2 metadata filter against the real canvas store, removing an obsolete retrieval config, and preserving unrelated fields after a partial title/retry update. I would then run the focused Web unit tests plus relevant lint/type checks before opening any PR.

    Could you assign #45443 to me (GYJ99) if this scope makes sense? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.18.0project#dify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions