Opened 15 years ago

Closed 14 years ago

Last modified 13 years ago

#13584 closed Bug (fixed)

django.forms FileField does not allow empty files.

Reported by: James Henstridge Owned by: Flaviu Simihaian
Component: File uploads/storage Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The FileField.clean() method raises ValidationError if the uploaded file is empty.

While this is useful in many cases, there are times when it is useful to allow empty files. Since the check is mixed in with the other validation checks, it isn't very easy to disable the check in a subclass without reimplementing the entire clean() method.

It would be nice if FileField could be directly configured to disable the empty check.

Attachments (3)

allow_empty_file_formfield_sloppy_test.diff (2.4 KB ) - added by Sasha Romijn 15 years ago.
allow_empty_file_formfield.diff (2.4 KB ) - added by Sasha Romijn 15 years ago.
13584.diff (2.5 KB ) - added by Flaviu Simihaian 14 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 by James Henstridge, 15 years ago

comment:2 by Adam Nelson, 15 years ago

Component: UncategorizedFile uploads/storage

comment:3 by Sasha Romijn, 15 years ago

milestone: 1.3
Needs documentation: set
Needs tests: set
Owner: changed from nobody to Sasha Romijn
Status: newassigned
Triage Stage: UnreviewedAccepted
Version: 1.1SVN

by Sasha Romijn, 15 years ago

comment:4 by Sasha Romijn, 15 years ago

Has patch: set
Needs documentation: unset
Needs tests: unset
Owner: changed from Sasha Romijn to nobody
Status: assignednew

comment:5 by Sasha Romijn, 15 years ago

I've been asked offline why I called the parameter allow_empty_file.

The consideration for this is to have a clear distinction between "must you upload a file, for the form validation to succeed" and "must the file be greater than 0 bytes". By calling it "blank", as suggested, for me this would feel like the former, where allow_empty file clearly refers to the latter.

comment:6 by James Henstridge, 14 years ago

The attached patch looks like it would suit my needs. The documentation change looks slightly wrong: it says that FileField has a single optional argument (allow_empty_file). But looking at the code, there is a second optional argument (max_length).

comment:7 by Flaviu Simihaian, 14 years ago

Owner: changed from nobody to Flaviu Simihaian

I updated the patch, test, and docs for 1.3.

by Flaviu Simihaian, 14 years ago

Attachment: 13584.diff added

comment:8 by Jannis Leidel, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

comment:10 by Chris Beaven, 14 years ago

Resolution: fixed
Status: newclosed

In [16090]:

Fixed #13584 -- Optionally allow empty files with django.forms.FileField. Thanks for the patch erickr and closedbracket.

comment:11 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top