Opened 10 years ago
Closed 10 years ago
#22891 closed Cleanup/optimization (fixed)
Document that "collectstatic --clear" deletes all files in the storage directory
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Coen van der Kamp | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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.
Attachments (1)
Change History (8)
comment:1 by , 10 years ago
Component: | contrib.staticfiles → Documentation |
---|---|
Summary: | Dangerous / Surprising Behavior of "collectstatic --clear" → Document that "collectstatic --clear" deletes all files in the storage directory |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 10 years ago
Easy pickings: | set |
---|
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.
comment:3 by , 10 years ago
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."
comment:4 by , 10 years ago
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.
comment:5 by , 10 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:6 by , 10 years ago
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
.
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In the
FileSystemStorage
case,MEDIA_ROOT
andSTATIC_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, 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.