Why is collectstatic adding back files I deleted to my Wagtail project?

563 views Asked by At

So I'm deploying a Wagtail project to a droplet on DigitalOcean and the collectstatic step keeps failing because of a post-processing failure. I didn't need the directory that was failing, so I removed it from my project. But somehow that old directory keeps coming back every time I try to run collectstatic and the post-processing keeps failing on a file that no longer exists but seems to be haunting my server somehow.

Here are the things I have tried:

  1. Deleting the static directory entirely
  2. Deleting the offending directory (peakjob) from my repository and running git clean to remove all untracked files from my server
  3. Deleting my entire project directory, creating a new virtualenv and cloning a fresh copy of my project with the offending directory removed
  4. Logging off my server and logging back on again
  5. Running collectstatic --clear (which doesn't seem to delete anything when I run it)
  6. Quitting terminal and restarting that, then logging back onto my server
  7. Destroying my entire droplet then creating a new one, creating a new virtualenv and cloning a fresh copy of my project without the offending directory in it.

Whenever I run collectstatic, it still is somehow adding back the offending directory I deleted and failing on it even after I blew up everything and started a completely fresh deployment. Is there some cache-like thing in Django that needs to be cleared? Where else could Django possibly be referencing this directory that no longer exists? If anyone has any ideas, I'm all ears.

Here's the error code log for anyone who wants a look at that:

Post-processing 'oldcodingprojects/peakjob/css/font-awesome.min.css' failed!

Traceback (most recent call last):

File "manage.py", line 24, in <module>
    main()
  File "manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
    collected = self.collect()
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 134, in collect
    raise processed
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 288, in _post_process
    content = pattern.sub(converter, content)
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 187, in converter
    hashed_url = self._url(
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 126, in _url
    hashed_name = hashed_name_func(*args)
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 338, in _stored_name
    cache_name = self.clean_name(self.hashed_name(name))
  File "/home/mkvportfolio/mvportfolio/.venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 88, in hashed_name
    raise ValueError("The file '%s' could not be found with %r." % (filename, self))
1

There are 1 answers

0
allcaps On

It is hard to say what exactly goes wrong.

collectstatic is a Django command. Wagtail seems unrelated.

Assuming you have these settings:

STATIC_ROOT = BASE_DIR / "static"
STATIC_URL = "/static/"

Your webserver should be configured to serve requests starting with /static/ directly from STATIC_ROOT directory. All other requests should be pointed to the Django application. The webserver should never serve files that live in the virtual environment.

This is where collectstatic comes in. It will copy static files from the virtual environment and your project to the STATIC_ROOT directory. To make them public available.

After, the copy some file storage backends might do a post processing step. For example create unique hashes and invalidate cache.

Why does collectstatic try to post process a file, that doesn't exist. A file that is copied there by collectstatic itself?

  • Put print(STATIC_ROOT) in your settings, and run collectstatic. The exact directory is printed.
  • Inspect the directory, does it exist? Does it have correct read write permissions?
  • list the contents of the directory, see if expected files are available.
  • Run collectstatic --no-post-process, is it only the post process step?
  • Create an empty font-awesome.min.css in the expected location
  • collectstatic on your local computer, does it fail too?
  • ...

Happy debugging.