#25528: `FileField(null=True)` doesn't work as expected
-------------------------------------+-------------------------------------
Reporter: mrmachine | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.8
(models, ORM) | Keywords: FileField null empty
Severity: Normal | string
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Given this model:
{{{
class Foo(models.Model):
foo_file = models.FileField(null=True)
}}}
which allows null values, if I create a foo object, the `foo_file` field
appears to be `None` by default, as I would expect. But on save, it is
converted to an empty string:
{{{
>>> f = Foo()
>>> f.foo_file.name == ''
False
>>> f.foo_file.name == None
True
>>> f.save()
>>> f = Foo.objects.get()
>>> f.foo_file == ''
True
}}}
This is both unexpected, and also makes `null=True` a bit pointless for
`FileField`.
If it is really by design that file fields cannot be null, setting
`null=True` on the field should be an error and the field should have
`default=''` by default. Although I think it would be better for
`FileField(null=True)` to work more like other fields.
--
Ticket URL: <https://code.djangoproject.com/ticket/25528>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.66d1abf26f66ee302113983918333395%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.