#16703 closed Bug (fixed)
collectstatic management command looks in current working dir instead of project root
| Reported by: | Daniel Naab | 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 by , 14 years ago
| Resolution: | → needsinfo |
|---|---|
| Status: | new → closed |
follow-up: 6 comment:2 by , 14 years ago
| Resolution: | needsinfo |
|---|---|
| Status: | closed → 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 by , 14 years ago
| Triage Stage: | Unreviewed → 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 yourSTATICFILES_FINDERSsetting, it will look for static files in the default file storage as defined by theDEFAULT_FILE_STORAGEsetting.
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
DefaultStorageFinderfrom 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 by , 14 years ago
The default value MEDIA_ROOT = '' had a role in this problem, see https://code.djangoproject.com/ticket/16504#comment:6
comment:5 by , 14 years ago
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 by , 14 years ago
Replying to danielnaab:
Some more details: On a clean
django-admin.pycreated project, I tracked it down todjango.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 by , 14 years ago
| Triage Stage: | Design decision needed → 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:9 by , 14 years ago
| Component: | Core (Management commands) → contrib.staticfiles |
|---|
This sounds like a configuration issue with the
STATIC_ROOTorSTATICFILES_DIRSand works for me. Feel free to reopen with further explanation to reproduce.