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: | 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)
Change History (8)
comment:1 by , 13 years ago
Component: | Uncategorized → File uploads/storage |
---|
comment:2 by , 13 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:3 by , 13 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
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 , 13 years ago
Attachment: | 17812.diff added |
---|
This is a patch which helped me to solve the problem.
comment:4 by , 13 years ago
Has patch: | set |
---|
comment:5 by , 13 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:6 by , 12 years ago
Status: | reopened → new |
---|
comment:7 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
It looks like ea3fe78a9d742904f6902cdc353a11d795418105 will prevent this.
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
ImageField
, without providing any value —instance = MyModel.objects.get(pk=1); instance.my_image = None; instance.save()
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.