Opened 7 years ago
Closed 6 years ago
#28595 closed New feature (fixed)
Database "execute hooks" for instrumentation
Reported by: | Shai Berger | Owned by: | Shai Berger |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Adam Johnson, Carl Meyer | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Quoting, editing and summarizing 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)
Change History (5)
comment:1 by , 7 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
comment:3 by , 7 years ago
Has patch: | unset |
---|
comment:4 by , 6 years ago
I might be missing something here, so I am not changing the state myself. But I believe this instrumentation has been successfully added in 2.0? As found at https://docs.djangoproject.com/en/2.2/topics/db/instrumentation/
comment:5 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Thanks Raphael, yes this feature was merged in 2.0, the ticket was just left in limbo as open. Closing now.
(I was a little confused about the meaning of the "needs tests" and "needs docs" flags)