#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)
Change History (14)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
Component: | Uncategorized → File uploads/storage |
---|
comment:3 by , 15 years ago
milestone: | → 1.3 |
---|---|
Needs documentation: | set |
Needs tests: | set |
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
Version: | 1.1 → SVN |
by , 15 years ago
Attachment: | allow_empty_file_formfield_sloppy_test.diff added |
---|
by , 15 years ago
Attachment: | allow_empty_file_formfield.diff added |
---|
comment:4 by , 15 years ago
Has patch: | set |
---|---|
Needs documentation: | unset |
Needs tests: | unset |
Owner: | changed from | to
Status: | assigned → new |
comment:5 by , 15 years ago
comment:6 by , 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).
by , 14 years ago
Attachment: | 13584.diff added |
---|
comment:8 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:9 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
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.