[Django] #28148: bahviour change on ImageField because of django.core.validators.validate_image_file_extension

12 views
Skip to first unread message

Django

unread,
Apr 28, 2017, 9:09:52 AM4/28/17
to django-...@googlegroups.com
#28148: bahviour change on ImageField because of
django.core.validators.validate_image_file_extension
-----------------------------------------+------------------------
Reporter: rm_ | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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'
```

--
Ticket URL: <https://code.djangoproject.com/ticket/28148>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 28, 2017, 9:11:21 AM4/28/17
to django-...@googlegroups.com
#28148: bahviour change on ImageField because of
django.core.validators.validate_image_file_extension
-------------------------------+--------------------------------------

Reporter: rm_ | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by rm_:

Old 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'
> ```

New 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'
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:1>

Django

unread,
Apr 28, 2017, 9:12:55 AM4/28/17
to django-...@googlegroups.com
#28148: behaviour change on ImageField because of
django.core.validators.validate_image_file_extension
-------------------------------+--------------------------------------

Reporter: rm_ | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by rm_:

Old 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'
> }}}

New description:

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'
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:2>

Django

unread,
Apr 28, 2017, 9:25:56 AM4/28/17
to django-...@googlegroups.com
#28148: behaviour change on ImageField because of
django.core.validators.validate_image_file_extension
-------------------------------+--------------------------------------

Reporter: rm_ | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Tim Graham):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:3>

Django

unread,
Apr 28, 2017, 9:31:16 AM4/28/17
to django-...@googlegroups.com
#28148: behaviour change on ImageField because of
django.core.validators.validate_image_file_extension
-------------------------------+--------------------------------------

Reporter: rm_ | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by rm_):

Replying to [comment:3 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

--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:4>

Django

unread,
Apr 28, 2017, 1:22:21 PM4/28/17
to django-...@googlegroups.com
#28148: Document addition of validate_image_file_extension() as a backwards
incompatible change for ImageField
--------------------------------------+------------------------------------
Reporter: rm_ | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Cleanup/optimization
* component: Forms => Documentation
* easy: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:5>

Django

unread,
May 6, 2017, 1:25:09 PM5/6/17
to django-...@googlegroups.com
#28148: Document addition of validate_image_file_extension() as a backwards
incompatible change for ImageField
--------------------------------------+------------------------------------
Reporter: rm_ | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by rm_):

* has_patch: 0 => 1


Comment:

PR here https://github.com/django/django/pull/8466

--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:6>

Django

unread,
May 11, 2017, 7:39:30 PM5/11/17
to django-...@googlegroups.com
#28148: Document addition of validate_image_file_extension() as a backwards
incompatible change for ImageField
--------------------------------------+------------------------------------
Reporter: rm_ | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"bdf192c59357a0d8117f6f34c94fb32a51e7a774" bdf192c5]:
{{{
#!CommitTicketReference repository=""
revision="bdf192c59357a0d8117f6f34c94fb32a51e7a774"
Fixed #28148 -- Doc'd ImageField name validation concerns with the test
client.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:7>

Django

unread,
May 11, 2017, 7:40:06 PM5/11/17
to django-...@googlegroups.com
#28148: Document addition of validate_image_file_extension() as a backwards
incompatible change for ImageField
--------------------------------------+------------------------------------
Reporter: rm_ | Owner: nobody

Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"643413f654d52ca4d7bf6d9402ff9ca24d2ea635" 643413f6]:
{{{
#!CommitTicketReference repository=""
revision="643413f654d52ca4d7bf6d9402ff9ca24d2ea635"
[1.11.x] Fixed #28148 -- Doc'd ImageField name validation concerns with
the test client.

Backport of bdf192c59357a0d8117f6f34c94fb32a51e7a774 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28148#comment:8>

Reply all
Reply to author
Forward
0 new messages