[PR #28948] fix: treat empty default values for optional file inputs as unset #32248

Closed
opened 2026-02-21 20:51:02 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: Yes


Summary

This PR fixes a validation bug where optional file/file-list variables fail validation when no file is uploaded.

  • Treats empty string (frontend's default) or empty list as unset for optional file inputs
  • Returns None instead of passing invalid values to type validation
  • Maintains backward compatibility with required file variables

fixes #28947

Root Cause

After commit 3841e8578f, optional variables with None values are replaced with their default values before validation. However, the frontend sets default: '' for all variable types, including file types. When this empty string reaches file type validation, it fails because a string is not a valid file object.

Changes

  • File: api/core/app/apps/base_app_generator.py
  • Function: _validate_inputs
  • Logic: Before file type validation, check if the value is an empty placeholder (empty string or empty list) for optional file inputs. If so, return None to skip validation.

Test Plan

  • Create a workflow with an optional file variable, run without uploading - should succeed
  • Create a workflow with an optional file-list variable, run without uploading - should succeed
  • Create a workflow with a required file variable, run without uploading - should still fail with "is required" error
  • Upload a file to an optional file variable - should work normally

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 dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/28948 **State:** closed **Merged:** Yes --- ## Summary This PR fixes a validation bug where optional file/file-list variables fail validation when no file is uploaded. - Treats empty string (frontend's default) or empty list as unset for optional file inputs - Returns `None` instead of passing invalid values to type validation - Maintains backward compatibility with required file variables fixes #28947 ## Root Cause After commit `3841e8578f`, optional variables with `None` values are replaced with their default values before validation. However, the frontend sets `default: ''` for all variable types, including file types. When this empty string reaches file type validation, it fails because a string is not a valid file object. ## Changes - **File:** `api/core/app/apps/base_app_generator.py` - **Function:** `_validate_inputs` - **Logic:** Before file type validation, check if the value is an empty placeholder (empty string or empty list) for optional file inputs. If so, return `None` to skip validation. ## Test Plan - [x] Create a workflow with an optional `file` variable, run without uploading - should succeed - [x] Create a workflow with an optional `file-list` variable, run without uploading - should succeed - [x] Create a workflow with a **required** `file` variable, run without uploading - should still fail with "is required" error - [x] Upload a file to an optional file variable - should work normally ## 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!) - [ ] 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 `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:51:02 -05:00
yindo closed this issue 2026-02-21 20:51:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32248