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: nina@… 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)

collectstatic_clear.patch (1.9 KB ) - added by Coen van der Kamp 10 years ago.
Collect static clear message.

Download all attachments as: .zip

Change History (8)

comment:1 by Tim Graham, 10 years ago

Component: contrib.staticfilesDocumentation
Summary: Dangerous / Surprising Behavior of "collectstatic --clear"Document that "collectstatic --clear" deletes all files in the storage directory
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

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, 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.

comment:2 by Daniele Procida, 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 anonymous, 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."

by Coen van der Kamp, 10 years ago

Attachment: collectstatic_clear.patch added

Collect static clear message.

comment:4 by Coen van der Kamp, 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 Coen van der Kamp, 10 years ago

Cc: Coen van der Kamp added
Has patch: set

comment:6 by Tim Graham, 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 Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In faacc54ac8601e8bdbfdc8651d68267d570a9c4b:

Fixed #22891 -- Clarified that collecstatic --clear with delete all files in the storage location.

Note: See TracTickets for help on using tickets.
Back to Top