Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#16703 closed Bug (fixed)

collectstatic management command looks in current working dir instead of project root

Reported by: danielnaab Owned by: nobody
Component: contrib.staticfiles Version: 1.3
Severity: Normal Keywords:
Cc: danielnaab@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

    ./manage.py collectstatic

Works as intended. However, if I script this call from a different working directory, collectstatic adds the working directory to the search path. This doesn't just copy more than is required, but I believe is creating an infinite copy loop, as it eventually starts iterating over the target static directory as well.

    cd
    ~/src/my_proj/manage.py collectstatic

or:

    cd
    src/my_project/manage.py collectstatic

both will copy every static folder under my home directory.

Change History (9)

comment:1 Changed 5 years ago by Jannis Leidel

Resolution: needsinfo
Status: newclosed

This sounds like a configuration issue with the STATIC_ROOT or STATICFILES_DIRS and works for me. Feel free to reopen with further explanation to reproduce.

comment:2 Changed 5 years ago by danielnaab

Resolution: needsinfo
Status: closedreopened

Some more details: On a clean django-admin.py created project, I tracked it down to django.contrib.staticfiles.finders.DefaultStorageFinder. STATICFILES_DIRS is empty, STATIC_ROOT is an arbitrary absolute path.

comment:3 Changed 5 years ago by Aymeric Augustin

Triage Stage: UnreviewedDesign decision needed

DefaultStorageFinder is disabled by default.

Indeed, when you enable it, with everything else set to the default values, it will find every files inside MEDIA_ROOT (the default location of FileSystemStorage). If you haven't set MEDIA_ROOT to something other than the empty string, it will find every file in the current directory!

The docs are a bit short on explanations on the purpose of this finder:

https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders:

One finder is disabled by default: django.contrib.staticfiles.finders.DefaultStorageFinder. If added to your STATICFILES_FINDERS setting, it will look for static files in the default file storage as defined by the DEFAULT_FILE_STORAGE setting.

https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DEFAULT_FILE_STORAGE:

Default: django.core.files.storage.FileSystemStorage
Default file storage class to be used for any file-related operations that don't specify a particular storage system. See Managing files.


There are several things we can do:

  • remove DefaultStorageFinder from the default project template, or add a warning;
  • better explain the purpose of this finder in the docs — defaulting to listing all media files in particularly confusing — unless it's a media => static compatibility tool?

comment:4 Changed 5 years ago by Aymeric Augustin

The default value MEDIA_ROOT = '' had a role in this problem, see https://code.djangoproject.com/ticket/16504#comment:6

comment:5 Changed 5 years ago by Jannis Leidel

Yeah, the DefaultStorageFinder finder is the compatibility layer between the file upload system and staticfiles. If you set MEDIA_ROOT and upload there, you might (!) want to include those files when collecting files.

comment:6 in reply to:  2 Changed 5 years ago by Jannis Leidel

Replying to danielnaab:

Some more details: On a clean django-admin.py created project, I tracked it down to django.contrib.staticfiles.finders.DefaultStorageFinder. STATICFILES_DIRS is empty, STATIC_ROOT is an arbitrary absolute path.

For the record, the DefaultStorageFinder has nothing to do with STATICFILES_DIRS. It's the empty MEDIA_ROOT setting which is the problem.

comment:7 Changed 5 years ago by Jacob

Triage Stage: Design decision neededAccepted

It seems like this is a configuration issue, but it also seems like collectstatic ought to warn about this problem when it sees the empty MEDIA_ROOT setting. I'm marking accepted, though I'm not clear if this is just a documentation fix or something else. Jannis, please feel free to re-close it if I'm wrong in my analysis.

comment:8 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: reopenedclosed

In [16863]:

Fixed #16703 -- Raise an exception if the storage location of the DefaultStorageFinder is empty.

comment:9 Changed 5 years ago by Jannis Leidel

Component: Core (Management commands)contrib.staticfiles
Note: See TracTickets for help on using tickets.
Back to Top