[Django] #20660: Filefield.delete() on empty field delete MEDIA_ROOT

5 views
Skip to first unread message

Django

unread,
Jun 26, 2013, 9:31:06 AM6/26/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
--------------------------------------+------------------------------
Reporter: stanislas.guerra@… | Owner: nobody
Type: Bug | Status: new
Component: File uploads/storage | Version: 1.4
Severity: Normal | Keywords: FileField delete
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------
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 ?

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

Django

unread,
Jun 26, 2013, 9:48:12 AM6/26/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
-------------------------------------+-------------------------------------

Reporter: stanislas.guerra@… | Owner: nobody
Type: Bug | Status: new
Component: File | Version: 1.4
uploads/storage | Resolution:
Severity: Normal | Triage Stage:
Keywords: FileField delete | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by stanislas.guerra@…):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I should have mention that MEDIA_ROOT is not deleted (only the symlink
is.)

--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:1>

Django

unread,
Jun 27, 2013, 4:35:39 AM6/27/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
--------------------------------------+------------------------------------

Reporter: stanislas.guerra@… | Owner: nobody
Type: Bug | Status: new
Component: File uploads/storage | Version: master
Severity: Normal | Resolution:
Keywords: FileField delete | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* version: 1.4 => master
* stage: Unreviewed => Accepted


Comment:

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 call `storage.delete` when `self._file` is None
* `FileSystemStorage` should not try to remove a path when its `delete`
method receives `''` as argument.

--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:2>

Django

unread,
Jun 27, 2013, 4:54:38 AM6/27/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
--------------------------------------+------------------------------------
Reporter: stanislas.guerra@… | Owner: claudep
Type: Bug | Status: assigned

Component: File uploads/storage | Version: master
Severity: Normal | Resolution:
Keywords: FileField delete | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* status: new => assigned
* owner: nobody => claudep


--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:3>

Django

unread,
Jun 27, 2013, 5:19:26 AM6/27/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
--------------------------------------+------------------------------------
Reporter: stanislas.guerra@… | Owner: claudep
Type: Bug | Status: assigned
Component: File uploads/storage | Version: master
Severity: Normal | Resolution:
Keywords: FileField delete | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/1310

--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:4>

Django

unread,
Jun 29, 2013, 11:55:53 AM6/29/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
-------------------------------------+-------------------------------------

Reporter: stanislas.guerra@… | Owner: claudep
Type: Bug | Status: assigned
Component: File | Version: master
uploads/storage | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: FileField delete | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:5>

Django

unread,
Jun 29, 2013, 12:10:41 PM6/29/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
-------------------------------------+-------------------------------------
Reporter: stanislas.guerra@… | Owner: claudep
Type: Bug | Status: closed
Component: File | Version: master
uploads/storage | Resolution: fixed

Severity: Normal | Triage Stage: Ready for
Keywords: FileField delete | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"7fbab3ebaf8b60bbe847b772f895df47067a60d3"]:
{{{
#!CommitTicketReference repository=""
revision="7fbab3ebaf8b60bbe847b772f895df47067a60d3"
Do not allow FileSystemStorage.delete to receive an empty name

Refs #20660.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:7>

Django

unread,
Jun 29, 2013, 12:10:41 PM6/29/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
-------------------------------------+-------------------------------------
Reporter: stanislas.guerra@… | Owner: claudep
Type: Bug | Status: closed
Component: File | Version: master
uploads/storage | Resolution: fixed
Severity: Normal | Triage Stage: Ready for
Keywords: FileField delete | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ea3fe78a9d742904f6902cdc353a11d795418105"]:
{{{
#!CommitTicketReference repository=""
revision="ea3fe78a9d742904f6902cdc353a11d795418105"
Fixed #20660 -- Do not try to delete an unset FieldFile

Thanks stanislas.guerra at gmail.com for the report and
Baptiste Mispelon for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:6>

Django

unread,
Jun 29, 2013, 12:13:15 PM6/29/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
-------------------------------------+-------------------------------------
Reporter: stanislas.guerra@… | Owner: claudep
Type: Bug | Status: closed
Component: File | Version: master
uploads/storage | Resolution: fixed
Severity: Normal | Triage Stage: Ready for
Keywords: FileField delete | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"a9b5a1e506a9e8492407399b8bec1c2a8420be60"]:
{{{
#!CommitTicketReference repository=""
revision="a9b5a1e506a9e8492407399b8bec1c2a8420be60"
[1.6.x] Do not allow FileSystemStorage.delete to receive an empty name

Refs #20660.
Backport of 7fbab3eba from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:9>

Django

unread,
Jun 29, 2013, 12:13:15 PM6/29/13
to django-...@googlegroups.com
#20660: Filefield.delete() on empty field delete MEDIA_ROOT
-------------------------------------+-------------------------------------
Reporter: stanislas.guerra@… | Owner: claudep
Type: Bug | Status: closed
Component: File | Version: master
uploads/storage | Resolution: fixed
Severity: Normal | Triage Stage: Ready for
Keywords: FileField delete | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"b6aed803b20cc7898a82fd65845e97676276f3fa"]:
{{{
#!CommitTicketReference repository=""
revision="b6aed803b20cc7898a82fd65845e97676276f3fa"
[1.6.x] Fixed #20660 -- Do not try to delete an unset FieldFile

Thanks stanislas.guerra at gmail.com for the report and
Baptiste Mispelon for the review.

Backport of ea3fe78a9d from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20660#comment:8>

Reply all
Reply to author
Forward
0 new messages