Opened 8 years ago

Last modified 8 years ago

#28148 closed Cleanup/optimization

bahviour change on ImageField because of django.core.validators.validate_image_file_extension — at Initial Version

Reported by: rm_ Owned by: nobody
Component: Documentation Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The following test code snippet stopped working on django 1.11 raising a validation error because the posted image has not a valid file extension:

`
class Test(TestCase):

def test_post(self):

img = BytesIO(IMAGE)
data = {

'image': img,

}
response = self.client.post(url, data=data)

`

The view takes the data and fill the following ModelForm that fails validation:

`
class Image(models.Model):

image = models.ImageField(_(u'Immagine'), upload_to='image')

class ImageForm(forms.ModelForm):

class Meta:

model = Image

`

As a workaround, adding a name attribute to the BytesIO object make the code work again:

`

img.name = 'ciao.jpg'

`

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top