[Django] #22891: Dangerous / Surprising Behavior of "collectstatic --clear"

15 views
Skip to first unread message

Django

unread,
Jun 23, 2014, 4:45:22 PM6/23/14
to django-...@googlegroups.com
#22891: Dangerous / Surprising Behavior of "collectstatic --clear"
-------------------------------------+--------------------
Reporter: nina@… | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.staticfiles | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+--------------------
When calling "collectstatic --clear," I would expect that only static
files would be deleted, but in fact all files in the static file folder
were deleted.

I am using storages and s3boto to serve static content and media. Here are
the related settings values:

INSTALLED_APPS = (
...
'storages',
...
'django.contrib.staticfiles',
...
)

AWS_STORAGE_BUCKET_NAME = "bucketname"
MEDIA_ROOT = ''
MEDIA_URL = "//%s.s3.amazonaws.com/" % AWS_STORAGE_BUCKET_NAME
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATIC_ROOT = os.path.join(VAR_ROOT, 'static')
STATIC_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME


When I ran "collectstatic --clear," the media files and the static files
were deleted, but I would expect that only static files would effected by
this call.

Ideally this command would only effect static files, but at the very least
there would be a warning in the documentation that this deletes all
content in the static folder.

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

Django

unread,
Jun 23, 2014, 7:03:52 PM6/23/14
to django-...@googlegroups.com
#22891: Document that "collectstatic --clear" deletes all files in the storage
directory
--------------------------------------+------------------------------------
Reporter: nina@… | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* component: contrib.staticfiles => Documentation
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

In the `FileSystemStorage` case, `MEDIA_ROOT` and `STATIC_ROOT` cannot be
the same, so you aren't likely to run into this issue. I guess django-
storage works a bit differently. But yes, it's not intended that you
storage media files and static files in the same location. In fact,
[https://docs.djangoproject.com/en/dev/ref/settings/#media-url we
document] "MEDIA_URL and STATIC_URL must have different values." If you'd
like to write a patch, I'll be happy to review and commit it.

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

Django

unread,
Jun 24, 2014, 3:34:54 AM6/24/14
to django-...@googlegroups.com
#22891: Document that "collectstatic --clear" deletes all files in the storage
directory
--------------------------------------+------------------------------------
Reporter: nina@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by EvilDMP):

* easy: 0 => 1


Comment:

To make it clear, this is the correct behaviour. Django can't tell whether
a particular file is a static file or not just by inspecting it.

Even if it removed only those that matched static files in the various
applications, that would neither guarantee complete removal nor
inadvertent removal, because applications' static files can change with
each version, or there may be static files left behind by an application
that's no longer installed.

The only safe thing to do is to clear the entire directory.

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

Django

unread,
Jun 24, 2014, 5:11:13 PM6/24/14
to django-...@googlegroups.com
#22891: Document that "collectstatic --clear" deletes all files in the storage
directory
--------------------------------------+------------------------------------
Reporter: nina@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by anonymous):

EvilDMP, I think this makes sense. In that case I think all that needs to
be more explicit is the warning message -- "This will delete all files in
the static directory, including files that are not managed by
staticfiles."

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

Django

unread,
Jul 17, 2014, 5:31:28 PM7/17/14
to django-...@googlegroups.com
#22891: Document that "collectstatic --clear" deletes all files in the storage
directory
--------------------------------------+------------------------------------
Reporter: nina@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by allcaps):

collectstatic --clear prints:

{{{
You have requested to collect static files at the destination
location as specified in your settings:

/Users/allcaps/path/to/project/static

This will DELETE EXISTING FILES!
Are you sure you want to do this?
}}}

The patch changes:

{{{
This will DELETE EXISTING FILES!
Are you sure you want to do this?
}}}

into:

{{{
'This will DELETE ALL FILES in the STATIC_ROOT directory!'
Are you sure you want to do this?
}}}

I'm not a fan of mentioning the unmanaged files.

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

Django

unread,
Jul 17, 2014, 7:18:34 PM7/17/14
to django-...@googlegroups.com
#22891: Document that "collectstatic --clear" deletes all files in the storage
directory
--------------------------------------+------------------------------------
Reporter: nina@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by allcaps):

* cc: allcaps (added)
* has_patch: 0 => 1


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

Django

unread,
Jul 23, 2014, 10:16:37 AM7/23/14
to django-...@googlegroups.com
#22891: Document that "collectstatic --clear" deletes all files in the storage
directory
--------------------------------------+------------------------------------
Reporter: nina@… | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by timo):

I'm going to go with "This will DELETE ALL FILES in this location!" If a
custom storage is in use, the location might not be controlled by
`STATIC_ROOT`.

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

Django

unread,
Jul 23, 2014, 10:17:34 AM7/23/14
to django-...@googlegroups.com
#22891: Document that "collectstatic --clear" deletes all files in the storage
directory
--------------------------------------+------------------------------------
Reporter: nina@… | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"faacc54ac8601e8bdbfdc8651d68267d570a9c4b"]:
{{{
#!CommitTicketReference repository=""
revision="faacc54ac8601e8bdbfdc8651d68267d570a9c4b"
Fixed #22891 -- Clarified that collecstatic --clear with delete all files
in the storage location.
}}}

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

Reply all
Reply to author
Forward
0 new messages