Opened 7 years ago

Closed 7 years ago

#7667 closed (fixed)

7814 breaks FileField.save_file for related objects

Reported by: oggy Owned by: axiak
Component: Database layer (models, ORM) Version: master
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: UI/UX:

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 7 years ago.

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by oggy

comment:1 Changed 7 years ago by jacob

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jacob
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 7 years ago by axiak

  • Keywords 2070-fix added
  • Owner changed from jacob to axiak
  • Status changed from assigned to new
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 7 years ago by Gulopine

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 Changed 7 years ago by Gulopine

  • Keywords fs-rf added

comment:5 Changed 7 years ago by jacob

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

(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