#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: allcaps 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 allcaps 12 months ago.
Collect static clear message.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 13 months ago by timo

  • Component changed from contrib.staticfiles to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Dangerous / Surprising Behavior of "collectstatic --clear" to Document that "collectstatic --clear" deletes all files in the storage directory
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/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 Changed 13 months ago by EvilDMP

  • 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 Changed 13 months ago 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."

Changed 12 months ago by allcaps

Collect static clear message.

comment:4 Changed 12 months ago 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.

comment:5 Changed 12 months ago by allcaps

  • Cc allcaps added
  • Has patch set

comment:6 Changed 12 months ago 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.

comment:7 Changed 12 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

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