﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28595	"Database ""execute hooks"" for instrumentation"	Shai Berger	Shai Berger	"Quoting, editing and summarizing [https://groups.google.com/forum/#!topic/django-developers/LembgKuRu7A/discussion a 5-month old thread from django-developers]:

Add the ability to install general instrumentation hooks around the database `execute()` and `executemany()` calls.

Such hooks would allow all sorts of interesting features. For one, they could replace the current special-case allowing `assertNumQueries()` & friends to record queries out of debug mode (it's an ugly hack, really), but they could also support other use cases:

* Prevent database access during execution of `render()` calls and serialization, to make sure all database access is being done explicitly in the view.
* Preventing database access during tests unless specifically requested by the test (per @carljm, pytest-django does this, currently via monkeypatching).
* Listen in on all executed queries for performance analysis (per @adamchainz, django-perf-rec currently monkey patches `connection.ops.last_executed_query` to achieve this)"	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed		Adam Johnson Carl Meyer	Accepted	0	0	0	0	0	0
