Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#202 closed defect (fixed)

Error when uploading image

Reported by: Steadicat Owned by: Adrian Holovaty
Component: Metasystem Version:
Severity: normal Keywords:
Cc: django@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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:

    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

Change History (2)

comment:1 by Steadicat, 19 years ago

Cc: django@… added

comment:2 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

Closing because it's old and may have been fixed.

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