Opened 6 years ago

Closed 6 years ago

#27383 closed Bug (worksforme)

Regression: `FileField(default=None)` now never upload a file through a ModelForm

Reported by: Maxime Lorant Owned by: nobody
Component: File uploads/storage Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Maxime Lorant)

We had in our code the following line (don't ask why, I don't know):

class SomeModel(models.Model):
     foo = ...
     bar = ...
     file = models.FileField(null=True, blank=True, default=None)


class SomeModelForm(forms.ModelForm):
     class Meta:
          fields = ('foo', 'bar', 'file', )

It was working until Django 1.9.x, but switching to Django 1.10, submission of files through a ModelForm stopped working. I found a solution by removing the useless default=None. Even though its usefulness can be questioned, it looks like it is a regression not documented in the release notes.

Should we bother adding it or change back the behaviour?

Change History (4)

comment:1 Changed 6 years ago by Maxime Lorant

Description: modified (diff)

comment:2 Changed 6 years ago by Tim Graham

Just to be sure, are you using Django 1.10.2? (see #27186 for a FileInput fix for fields with a default). As an aside, according to #10244, FileField can't be null anyway.

comment:3 Changed 6 years ago by Maxime Lorant

I am using Django 1.10.2. I could give a project example when I have the time and if I can reproduce it from scratch :-) I am using S3 but I don't think the storage used is important here.

comment:4 Changed 6 years ago by Tim Graham

Resolution: worksforme
Status: newclosed

I cannot reproduce a problem using this model and uploading through the default admin add/change view:

class FileModel(models.Model):
    file = models.FileField(default=None, null=True, blank=True)
Note: See TracTickets for help on using tickets.
Back to Top