networktocode / ntc-netbox-plugin-onboarding

A plugin for NetBox to easily onboard new devices.
Other
246 stars 47 forks source link

Enable Django debug toolbar unconditionally in development Dockerfile #16

Closed glennmatthews closed 4 years ago

glennmatthews commented 4 years ago

Normally, when DEBUG = True in the Django settings, netbox presents the django-debug-toolbar on requests whose source matches INTERNAL_IPS (by default, only 127.0.0.1 and ::1). When running in docker-compose, requests do not appear to be coming from localhost, but instead from the Docker bridge IP, which may vary.

Since this is explicitly a development environment for the plugin, not a production deployment, the easiest way to work around this is to use django-debug-toolbar's own method of overriding the logic that checks INTERNAL_IPS, and simply have it present the toolbar on a request from any source so long as DEBUG = True.

We have to provide this by patching netbox's settings.py, rather than in our standalone configuration.py, because settings.py explicitly only imports specific variables from configuration.py and this is not one of them.

glennmatthews commented 4 years ago

This causes some breakage in my additional view unit tests that I'm working on locally; looking into it.

glennmatthews commented 4 years ago

Okay, this appears to work. There seems to be some weirdness when running manage.py test wherein DEBUG is kind of "true but not really true", which caused any HTML view tests to fail due to loading but not really loading the debug toolbar. Adding an additional check to make sure we don't enable the debug toolbar when running manage.py test seems to have fixed this issue.