Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning shown if STATIC_ROOT directory missing in development #191

Open
edmorley opened this issue Aug 13, 2018 · 10 comments
Open

Warning shown if STATIC_ROOT directory missing in development #191

edmorley opened this issue Aug 13, 2018 · 10 comments

Comments

@edmorley
Copy link
Contributor

Hi! :-)

STR:

  1. Update existing Django+WhiteNoise project from whitenoise 3.3.1 to 4.0.
  2. Don't run collectstatic (ie since developing locally), so the directory referenced by STATIC_ROOT doesn't yet exist
  3. With Django's DEBUG = True, run ./manage.py runserver

Expected:

No console warnings about a missing static files directory.

Actual:

Warning in the console:

...
Django version 1.11.15, using settings 'treeherder.config.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
/usr/local/lib/python2.7/site-packages/whitenoise/base.py:97: UserWarning: No directory at: /app/treeherder/static/
  warnings.warn(u'No directory at: {}'.format(root))

Notes:

  • The warning was added to add_files() in 2a883f5.
  • We don't pre-create the STATIC_ROOT directory, since:
    • Django's collectstatic handles the creation of the directory automatically
    • To create the directory we'd either need to use the .gitkeep type approach (which then causes collectstatic to output misleading warnings/prompts about overwriting existing files) or else have additional local setup steps prior to running ./manage.py runserver.

A possible solution might be to have .add_files() take an optional ignore_missing=False argument, which is left as False everywhere apart from the Django middleware static root usage. eg:

if self.static_root:
    self.add_files(self.static_root, prefix=self.static_prefix, ignore_missing=self.autorefresh)

That said, should static_root even be added when run in DEBUG mode? The Django docs say not to place anything in the STATIC_ROOT directory directly, so it feels like there shouldn't be content there (though how many people go against that, I don't know).

@evansd
Copy link
Owner

evansd commented Aug 13, 2018

Thanks Ed, I hadn't considered this situation. I wonder if the correct behaviour would be just not to warn about missing directories if autorefresh is enabled. What do you think?

@edmorley
Copy link
Contributor Author

Yeah I think skipping the warning entirely if autorefresh enabled, might be the simplest thing :-)

evansd added a commit that referenced this issue Sep 11, 2018
This fixes the slightly annoying behaviur in #191 but also makes
conceptual sense: in autorefresh mode files and directories can not
exist when the application starts and be added later, so it doesn't make
sense to complain about their absence on startup.
@evansd evansd closed this as completed Sep 11, 2018
@urlsangel
Copy link

Hi

I've just started a new project with Whitenoise 4.0 and have exactly this problem - will there be a release that removes this warning in local dev?

Thanks.

@evansd
Copy link
Owner

evansd commented Sep 12, 2018

@urlsangel Yep, the 4.1 release should be out soon which will include this fix

@urlsangel
Copy link

@evansd

Great stuff, thanks for your work on this! 👍

evansd added a commit that referenced this issue Sep 12, 2018
This fixes the slightly annoying behaviur in #191 but also makes
conceptual sense: in autorefresh mode files and directories can not
exist when the application starts and be added later, so it doesn't make
sense to complain about their absence on startup.
vrajmohan pushed a commit to 18F/dsnap_rules that referenced this issue Feb 12, 2019
This stops WhiteNoise from complaining about a missing STATIC_ROOT
directory. See evansd/whitenoise#191.
haikoschol added a commit to haikoschol/vulnerablecode that referenced this issue Dec 19, 2019
This stops WhiteNoise from emitting warnings about STATIC_ROOT not
existing.
The alternative would be to set WHITENOISE_AUTOREFRESH = True in the
settings. We currently don't have any settings that are only applied
in CI and I think it makes sense to keep it that way to have the test
environment as close to production as possible.

See evansd/whitenoise#191

Signed-off-by: Haiko Schol <hs@haikoschol.com>
@TheBitShepherd
Copy link

@evansd - I'm using version 5.2.0 and still seeing this warning, is there something that I need to set on my end to eliminate this?

@kirankumbhar
Copy link

I can confirm what @Br4nd0R is saying. This issue is still there in 5.2.0

@michjnich
Copy link

Same here - 5.2.0 - I'm guessing a recent commit accidentally put it back in?

@pawelad
Copy link

pawelad commented Jun 25, 2022

Still here in 6.2.

@adamchainz adamchainz reopened this Jun 28, 2022
@banagale
Copy link

I noticed this while running tests locally.

This can be worked around either by:

  • Running ./manage.py collectstatic and having this dir exist before running tests.
  • Define a test runner which is referenced using the TEST_RUNNER setting, and in that runner add the setting: WHITENOISE_AUTOREFRESH = True

As for why this warning is being triggered even though it was though to have been fixed:

WhiteNoise.add_files() was changed late 2018 (after 4.1) from defining the root directory as:

root = root.rstrip(os.path.sep) + os.path.sep

to its current:

root = os.path.abspath(root)

The difference between these in 3.11 is the current version returns the path without the final forward slash.

That said, the test of existence, os.path.isdir(root) returns False for me either way (triggering a warning in each case).

The original commit merged in 4.1 seems to have included a test stub.

Currently, the test that should cover tests for the existence of a single warning.

I wonder if a warning is being issued but it isn't the one expected by the failed directory check

trey added a commit to piepworks/blaze-starter that referenced this issue May 4, 2023
I can't remember what all things I referenced to make this work. I've
been messing with it off and on all afternoon and evening createing and
recreating and recreating projects.

https://github.com/sloria/environs#reading-env-files

https://learndjango.com/tutorials/template-structure

evansd/whitenoise#191 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants