#27334: File uploads could rename temporary files rather than copying them
-------------------------------------+-------------------------------------
     Reporter:  Adam Chidlow         |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  File                 |                  Version:  1.10
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:  FileField,           |             Triage Stage:
  TemporaryUploadedFile              |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Adam Chidlow):

 * status:  closed => new
 * resolution:  duplicate =>


Comment:

 I'm pretty sure this is not a duplicate of #21602. From what I understand
 that ticket is talking about potential race conditions in a few different
 scenarios. In this case, the consequences of solving this ticket would
 solve one particular case of that ticket, but solving the linked ticket
 wouldn't necessarily do so in a way that solves this ticket as well.

 Furthermore, I think this ticket should just be a one-line fix.
 {{{
 def pre_save(self, model_instance, add):
     "Returns field's value just before saving."
     file = super(FileField, self).pre_save(model_instance, add)
     if file and not file._committed:
         # Commit the file to storage prior to saving the model
         file.save(file.name, file, save=False)
     return file
 }}}
 Should change the file.save call to:
 {{{
         file.save(file.name, file.file, save=False)
 }}}
 This will work, since the only times `_committed` is `False` is if the
 file has been deleted (in which case `bool(file)` is `False`), or a
 `FileField` has been set to an instance of `File` that is not also an
 instance of `FieldFile`, in which case passing the `File` object that was
 set to the field as the contents to `Storage.save` is perfectly valid.

--
Ticket URL: <https://code.djangoproject.com/ticket/27334#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.8c646a052150199e732819299cfc9703%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to