Opened 13 years ago

Closed 11 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

Description

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 image_field.name 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 13 years ago.
This is a patch which helped me to solve the problem.

Download all attachments as: .zip

Change History (8)

comment:1 by anonymous, 13 years ago

Component: UncategorizedFile uploads/storage

comment:2 by Aymeric Augustin, 13 years ago

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; instance.save()
  • 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 by anonymous, 13 years ago

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()
image.image.delete()

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 image.image.name is a blank string '' .
Therefore FileSystemStorage.delete method gets path to media symlink and deletes it.

by apiterimov, 13 years ago

Attachment: 17812.diff added

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

comment:4 by anonymous, 13 years ago

Has patch: set

comment:5 by Ramiro Morales, 13 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:6 by Aymeric Augustin, 12 years ago

Status: reopenednew

comment:7 by Tim Graham, 11 years ago

Resolution: fixed
Status: newclosed

It looks like ea3fe78a9d742904f6902cdc353a11d795418105 will prevent this.

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