Code

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#202 closed defect (fixed)

Error when uploading image

Reported by: Steadicat Owned by: adrian
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: UI/UX:

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

Attachments (0)

Change History (2)

comment:1 Changed 9 years ago by Steadicat

  • Cc django@… added

comment:2 Changed 8 years ago by adrian

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

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

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.