wger-project / docker

Production...ish docker-compose image for wger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DJANGO_DEBUG=False not being honoured

mattcen opened this issue · comments

My wger container has the DJANGO_DEBUG option set to False:

$ docker compose exec -T wgerweb env | grep DJANGO_DEBUG
DJANGO_DEBUG=False

But browsing to an invalid URL shows the Django debug page, including the text at the bottom:

You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

So it looks like this isn't being picked up by Django?

I can't quite tell which Dockerfile is being used to build the wger image on Docker Hub, so am unsure where to go to debug this. Is it the one in this directory?

Ah, I suspect it's because this line:

DEBUG = os.environ.get("DJANGO_DEBUG", True)

is interpreting the "False" environment variable as a string rather than a boolean, and is therefore reading it as True?

good catch! You are right, that's probably what's happening, the debug flag should be set to false anyway

the debug flag should be set to false anyway

By this do you mean you expect that is already the case, or that it should be changed to be False by default? Because it's currently not, as evidenced by the code quoted above. Obviously an easy fix though.

For my own Django projects, I tend to use django-environ for this, because it lets you cast variables to specific types and therefore handles cases like this correctly (see the DEBUG example I've linked), so switching to that is an option if you're happy with the additional dependency. Otherwise it shouldn't be too hard to do something like this after the existing line:

if type(DEBUG) is str:
    DEBUG = DEBUG.lower() in ['true', 'yes', 'on', '1']

But using an existing module may be more reliable and less error-prone. I can likely throw together a PR if you're happy to choose one of the above approaches.

[EDIT: For what it's worth, django-environ accepts the following boolean true strings: ('true', 'on', 'ok', 'y', 'yes', '1')]

I meant that it should be false by default (and during a quick test I just saw that if it's actually set to false django-compressor writes the files to a wrong folder, I'll correct that later today)

As for a PR, those are always welcome :) And skimming through django-eviron's docs, I'd say it's probably worth adding it as a new dependency