#20660 closed Bug (fixed)
Filefield.delete() on empty field delete MEDIA_ROOT
Reported by: | Owned by: | Claude Paroz | |
---|---|---|---|
Component: | File uploads/storage | Version: | dev |
Severity: | Normal | Keywords: | FileField delete |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Maybe this is because I use a symlink in my Apache configuration to serve the media :
$ ls -l /var/www/mysite.domain.com/documents/ -rw-r--r-- 1 www-data www-data 474 1 févr. 15:27 maintenance.html lrwxrwxrwx 1 root root 20 26 juin 15:02 media -> /data/media_mysite drwxr-xr-x 6 myuser www-data 4096 16 mai 12:01 static $ ls -l /data/media_mysite total 8 drwxrwsr-x 3 myuser www-data 4096 13 févr. 10:13 stuffs drwxrwsr-x 3 myuser www-data 4096 13 févr. 10:00 other_stuffs
But when I call delete() on an ImageField, if that very field is empty, the symlink is wipped out!
$ python manage.py shell In [1]: from myproject.myapp.models import MyModel In [2]: obj = MyModel.objects.get(euid="21439011") In [3]: obj.my_file Out[3]: <FieldFile: None> In [4]: obj.my_file.delete() $ ls -l /var/www/mysite.domain.com/documents/ -rw-r--r-- 1 www-data www-data 474 1 févr. 15:27 maintenance.html drwxr-xr-x 6 myproject www-data 4096 16 mai 12:01 static
Should not an exception be raised here instead ?
Change History (9)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.4 → master |
I could reproduce this. And yes, the deletion succeeds only when MEDIA_ROOT is a symlink (when it's a real directory, it will fail with OSError: [Errno 21] Is a directory: ...
at least on Linux).
I tend to think there are two bugs:
FieldFile
should not callstorage.delete
whenself._file
is NoneFileSystemStorage
should not try to remove a path when itsdelete
method receives''
as argument.
comment:3 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
I should have mention that MEDIA_ROOT is not deleted (only the symlink is.)