{{{
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.
* 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>
* owner: nobody => roebk
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:2>
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>
* has_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:4>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:5>
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>
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>
* owner: roebk => sztrovacsek
--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:8>
* needs_tests: 1 => 0
Comment:
https://github.com/django/django/pull/4262
--
Ticket URL: <https://code.djangoproject.com/ticket/23986#comment:9>
* 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>
* 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>
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>