Opened 2 months ago

Last modified 7 weeks ago

#28595 assigned New feature

Database "execute hooks" for instrumentation

Reported by: Shai Berger Owned by: Shai Berger
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Adam (Chainz) 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 (3)

comment:1 Changed 2 months ago by Shai Berger

Needs documentation: unset
Needs tests: unset

(I was a little confused about the meaning of the "needs tests" and "needs docs" flags)

comment:2 Changed 2 months ago by Tim Graham <timograham@…>

In d612026c:

Refs #28595 -- Added a hook to add execute wrappers for database queries.

Thanks Adam Johnson, Carl Meyer, Anssi Kääriäinen, Mariusz Felisiak,
Michael Manfre, and Tim Graham for discussion and review.

comment:3 Changed 7 weeks ago by Tim Graham

Has patch: unset
Note: See TracTickets for help on using tickets.
Back to Top