langgenius / langgenius/dify

Bug: Dify 1.17.0 stores an invalid selector when an optional tool file input is cleared

Open
#41,809 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
156k
Forks
24.6k
Avg merge
22h 9m
Merged PRs (30d)
610

Description

### 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 a bug report.
- [x] I searched existing open and closed issues.
- [x] I am submitting this report in English.
- [x] I did not modify the required issue sections.

### Dify version

1.17.0

### Cloud or Self Hosted

Self Hosted (Docker)

### Steps to reproduce

Use a plugin tool with an optional `file` or `files` form parameter. For example:

```yaml
parameters:
- name: image
type: files
required: false
label:
en_US: Reference images
human_description:
en_US: Optional reference images.
llm_description: Optional reference images.
form: form

- name: image_urls
type: string
required: false
label:
en_US: Reference image URLs
human_description:
en_US: Optional reference image URLs.
llm_description: Optional reference image URLs.
form: form
```

1. Create a workflow with a Start node containing an `Array[File]` input.
2. Add the plugin tool node.
3. Select `Start / input` for the optional `image` parameter.
4. Clear the selected variable.
5. Save or run the workflow.

The cleared input is persisted as an empty variable selector instead of an unset value:

```json
{"type":"variable","value":[]}
```

An empty string can also exist in serialized drafts:

```json
{"type":"variable","value":""}
```

This was re-verified against the Dify 1.17.0 release tag (`09a855dcef24c0edc7431c46c0cfaa494481daf5`) and current `main` (`0d8ad27b14d1efc19613b20018e5483fa93f8e5c`, 2026-09-04).

The 1.17.0 runtime conversion path produces these failures for the two empty selector forms:

```text
'': ValidationError: value must be a list
[]: ToolParameterError: Variable [] does not exist
```

Focused regression tests on current `main` also reproduce both sides before a fix:

- Frontend: 2 failures; clearing optional `file` and `files` inputs emits `{type: "variable", value: []}`.
- Backend: 4 failures; optional `file` and `files` inputs with `""` or `[]` are validated or resolved instead of treated as unset.

### ✔️ Expected Behavior

Clearing an optional `file` or `files` parameter should restore a canonical unset state, such as:

```json
{"type":"constant","value":null}
```

Existing drafts containing an empty optional variable selector should also run without trying to resolve that selector.

Required parameters and non-empty malformed selectors should retain their current validation behavior.

### ❌ Actual Behavior

Clearing an optional file selector keeps `type: "variable"` with an empty string or empty array value. Workflow execution then fails before the plugin is invoked with either `value must be a list` or `Variable [] does not exist`.

Contributor guide

Open the contributing guide

Research direction

Start with the focused frontend and backend regression tests described in the issue, which reproduce empty selectors for optional file and files parameters. Trace the serialization and runtime conversion paths for values of "" and []; done means cleared optional inputs become an unset value, existing empty selectors run without resolution errors, and required or non-empty malformed selectors keep their current validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
full-stack
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.