#18543: Non image file can be saved to ImageField
----------------------------------------------+--------------------
     Reporter:  johnsmith                     |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.4
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 https://docs.djangoproject.com/en/dev/ref/models/fields/#imagefield
     Inherits all attributes and methods from FileField, but also validates
 that the uploaded object is a valid image.


 I was trying to find out the exact exception that would be raised if a
 file is not an image and it appears that no such image validation is done.
 So I did a test, with a model such as this
 {{{
 class Image(models.Model):
     caption = models.Charfield(max_length=60)
     image = models.ImageField(upload_to='somewhere')

 }}}

 I tried this
 {{{
 f = django.core.files.base.ContentFile('not an image')
 i = myapp.models.Image()
 i.caption("This should throw an error but doesn't")
 i.image.save('bar.jpg', f)
 i.save()
 }}}

 I don't get any errors and the file is saved. Maybe I'm doing something
 wrong but from what the docs say I'm expecting to be prevented from doing
 this.

 From pip freeze
 Django==1.4
 PIL==1.1.7

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18543>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to