[Django] #23986: Collectstatic --clear fails if the static dir doesn't exist yet

14 views
Skip to first unread message

Django

unread,
Dec 12, 2014, 10:24:51 AM12/12/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+--------------------
Reporter: mvantellingen | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+--------------------
The --clear flag on collectstatic fails if the target directory doesn't
exist yet.

{{{
Traceback (most recent call last):
File "redacted/bin/manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "redacted/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "redacted/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "redacted/local/lib/python2.7/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "redacted/local/lib/python2.7/site-
packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "redacted/local/lib/python2.7/site-
packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "redacted/local/lib/python2.7/site-
packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 168, in handle_noargs
collected = self.collect()
File "redacted/local/lib/python2.7/site-
packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 89, in collect
self.clear_dir('')
File "redacted/local/lib/python2.7/site-
packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 202, in clear_dir
dirs, files = self.storage.listdir(path)
File "redacted/local/lib/python2.7/site-
packages/django/core/files/storage.py", line 270, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory:
'/redacted/public/static/2.1.0-dev'

}}}


Adding
{{{
if not os.path.exists(self.storage.location):
return
}}}

In Command.clear_dir() fixes the issue

--
Ticket URL: <https://code.djangoproject.com/ticket/23986>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 12, 2014, 3:44:04 PM12/12/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+------------------------------------
Reporter: mvantellingen | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by timgraham):

* needs_docs: => 0
* needs_better_patch: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:1>

Django

unread,
Dec 12, 2014, 4:55:47 PM12/12/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+------------------------------------
Reporter: mvantellingen | Owner: roebk
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by roebk):

* owner: nobody => roebk
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:2>

Django

unread,
Dec 12, 2014, 7:54:25 PM12/12/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+------------------------------------
Reporter: mvantellingen | Owner: roebk
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by roebk):

I've created a pull request for this ticket which can be viewed at
https://github.com/django/django/pull/3721. I hope I've done everything to
the correctly and to the required standard *fingers crossed*.

--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:3>

Django

unread,
Dec 12, 2014, 8:51:57 PM12/12/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+------------------------------------
Reporter: mvantellingen | Owner: roebk
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by berkerpeksag):

* has_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:4>

Django

unread,
Dec 14, 2014, 3:57:15 AM12/14/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+------------------------------------
Reporter: mvantellingen | Owner: roebk
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by berkerpeksag):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:5>

Django

unread,
Dec 15, 2014, 5:03:01 PM12/15/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+------------------------------------
Reporter: mvantellingen | Owner: roebk
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by roebk):

For a little guidance and to ensure I implement the tests in the best
possible way, what would be the best way in adding the test for a missing
target directory? Should I be looking at adding a new class something
along the lines of TestCollectionClearNoTargetDirectory?

For reference the current test of the ``--clear`` option is as follows:

{{{
class TestCollectionClear(CollectionTestCase):
"""
Test the ``--clear`` option of the ``collectstatic`` management
command.
"""
def run_collectstatic(self, **kwargs):
clear_filepath = os.path.join(settings.STATIC_ROOT, 'cleared.txt')
with open(clear_filepath, 'w') as f:
f.write('should be cleared')
super(TestCollectionClear, self).run_collectstatic(clear=True)

def test_cleared_not_found(self):
self.assertFileNotFound('cleared.txt')
}}}


Thanks in advance :)

--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:6>

Django

unread,
Dec 15, 2014, 8:58:39 PM12/15/14
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+------------------------------------
Reporter: mvantellingen | Owner: roebk
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by berkerpeksag):

You can just override the `STATIC_ROOT` setting and call
`self.run_collectstatic()`:

{{{#!py
@override_settings(STATIC_ROOT=os.path.join(TEST_ROOT, 'project',
'site_media', 'static-does-not-exist'))
def test_empty_directory(self):
self.run_collectstatic()
}}}

but, I think this is not the cleanest solution. You also don't need to
call `BaseCollectionTestCase.setUp()` because it tries to create a
directory if it doesn't exist:
https://github.com/django/django/blob/master/tests/staticfiles_tests/tests.py#L132

I'd go with a new test case (without using `BaseCollectionTestCase`
mixin).

--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:7>

Django

unread,
Mar 7, 2015, 7:33:57 AM3/7/15
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+-------------------------------------
Reporter: mvantellingen | Owner:
| sztrovacsek
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sztrovacsek):

* owner: roebk => sztrovacsek


--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:8>

Django

unread,
Mar 7, 2015, 9:39:43 AM3/7/15
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+-------------------------------------
Reporter: mvantellingen | Owner:
| sztrovacsek
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sztrovacsek):

* needs_tests: 1 => 0


Comment:

https://github.com/django/django/pull/4262

--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:9>

Django

unread,
Mar 7, 2015, 9:51:11 AM3/7/15
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+-------------------------------------
Reporter: mvantellingen | Owner:
| sztrovacsek
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


Comment:

Looks good to me, thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:10>

Django

unread,
Mar 7, 2015, 10:47:52 AM3/7/15
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+-------------------------------------
Reporter: mvantellingen | Owner:
| sztrovacsek
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"87d78241a2fc85e5715fb51c554fe06e91deee58"]:
{{{
#!CommitTicketReference repository=""
revision="87d78241a2fc85e5715fb51c554fe06e91deee58"
Fixed #23986 -- Fixed collectstatic --clear failure if STATIC_ROOT dir
doesn't exist.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:11>

Django

unread,
Mar 11, 2015, 2:49:33 PM3/11/15
to django-...@googlegroups.com
#23986: Collectstatic --clear fails if the static dir doesn't exist yet
-------------------------------------+-------------------------------------
Reporter: mvantellingen | Owner:
| sztrovacsek
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.7

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"389baccac5fce72c67cfed7a6ebcf9273edf9282" 389bacca]:
{{{
#!CommitTicketReference repository=""
revision="389baccac5fce72c67cfed7a6ebcf9273edf9282"
Fixed staticfiles test on Windows; refs #23986.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:12>

Reply all
Reply to author
Forward
0 new messages