Opened 16 years ago

Closed 16 years ago

#7667 closed (fixed)

7814 breaks FileField.save_file for related objects

Reported by: oggy Owned by: Michael Axiak
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: file upload FileField related, 2070-fix fs-rf
Cc: ognjen.maric@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

class Article(models.Model):
    body = models.CharField(max_length=200)
    class Admin:
        pass

class Attachment(models.Model):
    article = models.ForeignKey(Article, num_in_admin=1, num_extra_on_change=1, edit_inline=models.TABULAR)
    file = models.FileField(upload_to='uploads/attachments/%Y/%m/%d')
    keep = models.BooleanField(core=True, default=True, editable=False)
    remove = models.BooleanField(default=False)
    name = models.CharField(max_length=30)

Django admin breaks when attempting to create a new Article w/o any attachments. The problem is that after the introduction of MultiPartParser in 7814, request.POST contains an entry
u'attachment.0.file_file': [u'']
whereas that entry would be missing in prior revisions. This eventually leads to an entry of:
u'file_file': [u'']
instead of
u'file_file': []
in the new_data dict which is passed as the parameter to FileField.save_file, so this method eventually breaks. The fix is simple and I'm attaching a patch for it. The only thing is that I'm not sure if it would perhaps be better to handle this somewhere else?

Attachments (1)

save_file.diff (1.1 KB ) - added by oggy 16 years ago.

Download all attachments as: .zip

Change History (6)

by oggy, 16 years ago

Attachment: save_file.diff added

comment:1 by Jacob, 16 years ago

Owner: changed from nobody to Jacob
Status: newassigned

comment:2 by Michael Axiak, 16 years ago

Keywords: 2070-fix added
Owner: changed from Jacob to Michael Axiak
Status: assignednew
Triage Stage: UnreviewedAccepted

comment:3 by Marty Alchin, 16 years ago

I'll also be looking at this from the side of the impending filestorage refactor, so I'm also marking it fs-rf for now.

comment:4 by Marty Alchin, 16 years ago

Keywords: fs-rf added

comment:5 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [7906]) Fixed #7667: fixied FileField.save_file for inline related objects. This is really just papering over a bigger problem that should get fixed either by newforms-admin or the file-storage refactoring, but this fix makes the admin work until either of those things happen. Thanks, oggy.

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