Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#11149 closed (fixed)

error with def save_form_data --

Reported by: romankrv Owned by: kmtracey
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by kmtracey)

Hi everyone

I use django revision 10000 and it is normal. But when I update to revision more then 10200 that I get error:

cannot identify image fileRequest Method:	POST
Request URL:	http://127.0.0.1:8000/users/a1/
Exception Type:	IOError
Exception Value:	cannot identify image file
Exception Location:	/usr/lib/python2.5/site-packages/PIL/Image.py in open, line 1917
Python Executable:	/usr/bin/python2.5
Python Version:	2.5.4

My code where is problem is:

class ThumbnailImageField(models.ImageField):
    def save_form_data(self, instance, data):
        if data and isinstance(data, UploadedFile):
            im = Image.open(data).convert("RGB")

if I change data to constant path that it will be work without error

Attachments (1)

trackback.txt (29.3 KB) - added by romankrv 5 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 5 years ago by dc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Looks like #11055 duplicate. Does trunk head also has this error? And please post full traceback.

comment:2 Changed 5 years ago by romankrv

My ticket not alike #11055 because in #11055 about admin but my ticket work without admin

comment:3 Changed 5 years ago by dc

#11055 is not about admin, but about upload file rewinding (without it PIL can not recognize image). Please checkout curent trunk head (use svn co, not svn up) and post full traceback if you can confirm error.

Changed 5 years ago by romankrv

comment:4 Changed 5 years ago by romankrv

I make use svn co and get version beta 1 SVN-10825
but problem not disapears. So if i back to version to 10189 it work there.
I attach file with TrackBack :

comment:5 Changed 5 years ago by kmtracey

  • Description modified (diff)

Fixed formatting.

comment:6 Changed 5 years ago by kmtracey

  • milestone set to 1.1
  • Owner changed from nobody to kmtracey
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

This looks like a bug in code added in r10190 that is resulting in file-type fields having their save_form_data methods be called twice. First time through it works, 2nd time it fails. Not sure why it fails the 2nd time around (wild guess the file read pointer is at the wrong place by then) but it's not really worth tracking down since we shouldn't be calling the save method twice, and fixing that fixes the error.

comment:7 Changed 5 years ago by kmtracey

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [10826]) Fixed #11149 -- Don't call save_form_data on file-type fields multiple times when saving a model form.

comment:8 follow-up: Changed 5 years ago by romankrv

After update it not import
"from django.core.files.utils import FileProxyMixin"

comment:9 in reply to: ↑ 8 Changed 5 years ago by kmtracey

Replying to romankrv:

After update it not import
"from django.core.files.utils import FileProxyMixin"

That would seem to indicate your checkout is not complete. Do you have the file django/core/files/utils.py? It was added quite recently and the only thing in it is FileProxyMixin:

http://code.djangoproject.com/browser/django/trunk/django/core/files/utils.py

comment:10 Changed 5 years ago by romankrv

You are right. I haven't it but I reinstall it and it work. Bug is fixed.
Good work cooparete.

comment:11 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.