Opened 15 years ago
Closed 14 years ago
#12106 closed (fixed)
FileFields ignore initial data when required=False
Reported by: | Dave Hall | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you create a form containing a FileField
where required=False
, then the field will ignore any initial value passed in.
from django import forms from django.core.files import File class MyForm(forms.Form): file_field = forms.FileField(required=False) test_file = File(open("test.txt")) form = MyForm(data={}, initial={"file_field": test_file}) form.is_valid() # Force form validation. print form.cleaned_data["file_field"] # prints None
Given that an initial value was supplied, the cleaned_data
should now contain the initial value. However, it contains None, as the initial value has been silently discarded.
Attachments (1)
Change History (4)
by , 15 years ago
comment:1 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
comment:3 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
If you believe an issue has been resolved, then mark it closed. Trac is completely open for all to modify for exactly this reason. If it turns out you are mistaken, the original reporter can always reopen. In this case, you *are* the original reporter, so that's not likely to happen :-)
Looking over the Django source code, it would appear that this issue has been fixed. Many thanks!
Would it be okay to mark this as fixed?