﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
202	Error when uploading image	Steadicat	Adrian Holovaty	"When uploading an image with width and height fields, I get this error:

{{{
Traceback (most recent call last):

  File ""C:\Program Files\Python\lib\site-packages\django\core\meta.py"", line 1948, in save_file
    setattr(new_object, self.width_field, getattr(original_object, self.width_field))

AttributeError: 'NoneType' object has no attribute 'image_width'
}}}

source:django/trunk/django/core/meta.py#311, lines 1941 onwards:

{{{
#!python
    def save_file(self, new_data, new_object, original_object, change, rel):
        FileField.save_file(self, new_data, new_object, original_object, change, rel)
        # If the image has height and/or width field(s) and they haven't
        # changed, set the width and/or height field(s) back to their original
        # values.
        if change and (self.width_field or self.height_field):
            if self.width_field:
                setattr(new_object, self.width_field, getattr(original_object, self.width_field))
            if self.height_field:
                setattr(new_object, self.height_field, getattr(original_object, self.height_field))
            new_object.save()
}}}

When I upload the image for the first time original_object is None, so getattr(original_object, self.width_field) fails. It probably should not be executed.

The comment above the if condition says ""if they haven't changed"" but the code says ""if change"". One of them must be wrong.

Indeed ""if not change"" seems to fix it (though I couldn't try what happens when I don't change the image, see #201).

''mod_python on Windows''
"	defect	closed	Metasystem		normal	fixed		django@…	Unreviewed	0	0	0	0	0	0
