The purpose of the context process is to capture and expose SQL queries to the template, but only when DEBUG is True, and the current IP is in a safelist. It also exposes debug, but only when both those conditions are met. This is inconsistent with the term “debug” everywhere else in Django.
Could the context processor be renamed from debug to debug_sql for example?
In a perfect world, I’d like debug to mean settings.DEBUG, but changing this behaviour could have adverse consequences on projects.
Since it’s so trivial to define a context variable, I wonder if this is something left up to users to define.
Further, this context processor (and sql_queries) was implemented in one of Django’s first commits and has barely changed in 19 years. With today’s rich ecosystem and third party libs dedicated to profiling Django queries and performance, does it still make sense to provide this feature in the core framework.
Or, is it time to deprecate this context processor?
If there were to be a change made in this area, I could see removing it from the default context processors that are defined in the startproject template.
This would have no effect on any existing projects that could possibly be using it, and reduces its “visibility” or “prominence” for new projects being created - while maintaining its availability for those wanting to use it.
Its existance alone doesn’t prevent or prohibit a different context processor from being created or used to add a context variable named “debug” which mirrors the current setting. (You just wouldn’t be able to use the two of them together.) And as you point out, its maintenance load has been low, which implies that it’s not that big of an issue to keep it.
@marcgibbons I agree this context processor is a bit weird. Requiring both the DEBUG setting andINTERNAL_IPS is a strange combination, since Django recommends DEBUG never be used in production anyway. The same logic was copied in django-debug-toolbar
INTERNAL_IPS is weird anyway. It probably doesn’t fit most projects these days, since fewer companies use an intranet. To activate django-debug-toolbar, and I guess the debug context processor, most need to add INTERNAL_IPS = ["127.0.0.1"], which is kind of nonsense since 127.0.0.1 is by definition internal.
Oh wow, that is a super niche debugging aid. That can probably be deprecated with little concern. django-debug-toolbar probably fills that void for most people, or using the shell to call resolve()…
That’s this code?
Yeah, a bit weird to shout EXTERNAL on every email even when INTERNAL_IPS is not configured.