Opened 4 years ago

Closed 4 years ago

Last modified 4 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 4 years ago by jezdez

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

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 follow-up: Changed 4 years ago by danielnaab

  • Resolution needsinfo deleted
  • Status changed from closed to reopened

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 4 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Design 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 4 years ago by aaugustin

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

comment:5 Changed 4 years ago by jezdez

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 4 years ago by jezdez

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 4 years ago by jacob

  • Triage Stage changed from Design decision needed to Accepted

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 4 years ago by jezdez

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

In [16863]:

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

comment:9 Changed 4 years ago by jezdez

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