Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#28148 closed Cleanup/optimization (fixed)

Document addition of validate_image_file_extension() as a backwards incompatible change for ImageField

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 (last modified by rm_)

The following test code snippet stopped working after upgrading django to 1.11 from 1.10.x. The code now raises 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 (8)

comment:1 by rm_, 8 years ago

Description: modified (diff)

comment:2 by rm_, 8 years ago

Description: modified (diff)
Summary: bahviour change on ImageField because of django.core.validators.validate_image_file_extensionbehaviour change on ImageField because of django.core.validators.validate_image_file_extension

comment:3 by Tim Graham, 8 years ago

We could document the backwards incompatible change. Did you have anything else in mind?

in reply to:  3 comment:4 by rm_, 8 years ago

Replying to Tim Graham:

We could document the backwards incompatible change. Did you have anything else in mind?

I think a mention of ImageFields name attribute requirements should be added in the paragraph that suggests to use StringIO / BytesIO here:
https://docs.djangoproject.com/en/1.11/topics/testing/tools/#django.test.Client.post

comment:5 by Tim Graham, 8 years ago

Component: FormsDocumentation
Easy pickings: set
Summary: behaviour change on ImageField because of django.core.validators.validate_image_file_extensionDocument addition of validate_image_file_extension() as a backwards incompatible change for ImageField
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:7 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In bdf192c5:

Fixed #28148 -- Doc'd ImageField name validation concerns with the test client.

comment:8 by Tim Graham <timograham@…>, 7 years ago

In 643413f6:

[1.11.x] Fixed #28148 -- Doc'd ImageField name validation concerns with the test client.

Backport of bdf192c59357a0d8117f6f34c94fb32a51e7a774 from master

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