Opened 6 years ago

Closed 4 years ago

#17812 closed Bug (fixed)

Symlink link to media files is deleted after calling of delete method of ImageField if value of it field is None.

Reported by: piterimov@… Owned by: nobody
Component: File uploads/storage Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


If media folder for media files is symlink then after calling of delete method of ImageField model's field this symbolic link has been deleted if value of this field is None (i. e. value of is empty).
This was found for django 1.3.1 (but maybe and is for others). This is happening for ImageField only. FileField works good.

Attachments (1)

17812.diff (703 bytes) - added by apiterimov 6 years ago.
This is a patch which helped me to solve the problem.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by anonymous

Component: UncategorizedFile uploads/storage

comment:2 Changed 6 years ago by Aymeric Augustin

Resolution: worksforme
Status: newclosed

Here's what I understand from your report (I see you aren't a native speaker):

  • settings.MEDIA_ROOT is a symlink — for instance, /var/www/media -> /mnt/storage/media
  • you save a model that has an ImageField, without providing any value — instance = MyModel.objects.get(pk=1); instance.my_image = None;
  • the symlink gets deleted

I tried that, and I can't reproduce the problem. To be honest, it sounds extremely unlikely that Django would delete a directory or a symlink like that.

comment:3 Changed 6 years ago by anonymous

Resolution: worksforme
Status: closedreopened

It's happening when I try to delete image by image.delete() method.

It's better to show by an example.
Suppose for example we have some model:

class Image(models.Model):
    image = models.ImageField()
    class Meta:
        app_label = 'image'

Then we try to do following:

image = Image()

Thereafter symlink to media files will be deleted.

Also I was mistaken about the FileField : This is happening for it too.

Apparently this is happening because the name of image field is a blank string '' .
Therefore FileSystemStorage.delete method gets path to media symlink and deletes it.

Changed 6 years ago by apiterimov

Attachment: 17812.diff added

This is a patch which helped me to solve the problem.

comment:4 Changed 6 years ago by anonymous

Has patch: set

comment:5 Changed 6 years ago by Ramiro Morales

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:6 Changed 5 years ago by Aymeric Augustin

Status: reopenednew

comment:7 Changed 4 years ago by Tim Graham

Resolution: fixed
Status: newclosed

It looks like ea3fe78a9d742904f6902cdc353a11d795418105 will prevent this.

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