Django

Code

Ticket #7667 (closed: fixed)

Opened 5 months ago

Last modified 5 months ago

7814 breaks FileField.save_file for related objects

Reported by: oggy Assigned to: axiak
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: file upload FileField related, 2070-fix fs-rf
Cc: ognjen.maric@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

save_file.diff (1.1 kB) - added by oggy on 07/07/08 19:45:10.

Change History

07/07/08 19:45:10 changed by oggy

  • attachment save_file.diff added.

07/07/08 19:49:00 changed by jacob

  • owner changed from nobody to jacob.
  • needs_better_patch changed.
  • status changed from new to assigned.
  • needs_tests changed.
  • needs_docs changed.

07/08/08 13:27:11 changed by axiak

  • keywords changed from file upload FileField related to file upload FileField related, 2070-fix.
  • owner changed from jacob to axiak.
  • status changed from assigned to new.
  • stage changed from Unreviewed to Accepted.

07/08/08 18:14:37 changed 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.

07/08/08 18:14:50 changed by Gulopine

  • keywords changed from file upload FileField related, 2070-fix to file upload FileField related, 2070-fix fs-rf.

07/12/08 15:43:28 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #7667 (7814 breaks FileField.save_file for related objects)




Change Properties
Action