Repository navigation
6.0.0
-
pyinstrument is gated like the debug toolbar. With
DEBUG_PYINSTRUMENT,autoload()installscodenerix.debug_middleware.ProfilerMiddleware, a subclass of pyinstrument's middleware that only profiles requests accepted by the newcodenerix.debug.show_pyinstrument(a projectPYINSTRUMENT_SHOW_CALLBACK, if set, still applies on top). Before,pyinstrument.middleware.ProfilerMiddlewarewas appended toMIDDLEWARE, behind the page cache: any client could get a profile with?profile, and the profile page was cached and served to everyone asking for that URL, even with a restrictivePYINSTRUMENT_SHOW_CALLBACK. The profile page is sent withCache-Control: no-store. Projects that list pyinstrument's own middleware inMIDDLEWAREkeep it where it is; the gate then applies only if they setPYINSTRUMENT_SHOW_CALLBACK = "codenerix.debug.show_pyinstrument". - Debug requests (thosecodenerix.debug.is_debug_request()accepts) bypass Django's page cache: they are never served from it and never stored in it, and their responses carryCache-Control: no-store. When it installs a debug tool,autoload()replacesdjango.middleware.cache.UpdateCacheMiddleware,FetchFromCacheMiddlewareandCacheMiddlewareinMIDDLEWAREwith thecodenerix.debug_middlewaresubclasses of the same name, which behave as Django's for every other request. This closes two leaks the 5.3.3 placement left open with the toolbar on: the toolbar's own endpoints (__debug__/render_panel/and the like) were cacheable and then served to any client asking for the same URL, and instrumented responses carriedCache-Control: max-age=600. Toolbar captures are also always cache misses now. - The superuser check works for middlewares placed beforeSessionMiddlewareandAuthenticationMiddleware, where every debug middleware sits since 5.3.3. Withoutrequest.user, the gate reads the user from the session cookie, read-only: a session whose hash only verifies againstSECRET_KEY_FALLBACKSis rejected rather than rotated, so the gate never logs the request out. In 5.3.3 the superuser check silently failed closed at that position. -
One set of settings drives every debug tool (toolbar, debug_panel and pyinstrument), read per request by
codenerix.debug.is_debug_request():DEBUG_ALLOWED_IPSreplacesDEBUG_TOOLBAR_ALLOWED_IPS. When it is not defined, nobody sees the debug tools:INTERNAL_IPSand upstream's default callback no longer apply."0.0.0.0"still means any client (constant renamed tocodenerix.debug.DEBUG_ANY_IP).DEBUG_REQUIRE_SUPERUSERreplacesDEBUG_TOOLBAR_REQUIRE_SUPERUSERand defaults toTruewithDEBUGon or off (it defaulted tonot DEBUG). A development setup that should show the tools without logging in must set it toFalse.autoload(..., DEBUG_PRODUCTION=False)replacesDEBUG_TOOLBAR_PRODUCTION, and now also enables pyinstrument withDEBUG=False. The old keyword raisesTypeError.- The removed settings are not read as aliases: if any of them is still defined, system check
codenerix.E001reports it and every debug tool stays off.
-
With
DEBUG=False,"0.0.0.0"inDEBUG_ALLOWED_IPSrequiresDEBUG_REQUIRE_SUPERUSER = True; without a login, production needs an explicit list of client IPs. Same rule as before, under the new names. -
autoload()places pyinstrument's middleware like the toolbar's: at the start ofMIDDLEWAREor right afterGZipMiddleware, outside the toolbar ([profiler, toolbar, ...]). Projects withDEBUG=TrueandDEBUG_PYINSTRUMENT=Truesee it move from the end ofMIDDLEWAREto the start, and it now needsDEBUG_ALLOWED_IPS(and a superuser login, by default) to profile anything. -
The toolbar stands aside on requests carrying pyinstrument's URL argument (
PYINSTRUMENT_URL_ARGUMENT,profileby default) when a profiler middleware is inMIDDLEWARE: the profile replaces the response, so the two never run on the same request and the toolbar's cost stays out of the profile. WithPYINSTRUMENT_PROFILE_DIR(every request profiled to disk), requests without that argument still run the toolbar, and its cost is in those profiles. -
codenerix.debug.debug_toolbar_access_errorsis nowdebug_access_errors, and the system check functioncodenerix.checks.check_debug_toolbar_accessis nowcheck_debug_access. The check id stayscodenerix.E001. It now also reports a profiler middleware placed behind the page cache, stock page cache middlewares left inMIDDLEWAREnext to a debug tool (for instance when the project adds them after callingautoload()), and a toolbar middleware whoseDEBUG_TOOLBAR_CONFIG["SHOW_TOOLBAR_CALLBACK"]is notcodenerix.debug.show_toolbar(upstream's callback ignoresDEBUG_ALLOWED_IPS). The tool concerned fails closed on its own placement errors; a misplaced profiler does not switch the toolbar off, nor the other way round. Like anyError, these stoprunserverandmigrate.