django-query-guard Plugin Catches N+1 Database Queries During Django Testing
A developer has released django-query-guard, an open-source Pytest plugin designed to detect N+1 database query problems and enforce query limits directly within Django test suites. The tool addresses a common performance pitfall where Django's ORM silently triggers excessive database calls — for example, fetching 100 users and then executing 100 additional queries for related data. Using a simple pytest marker, developers can set a maximum query threshold per test, causing the test to fail immediately if the limit is exceeded along with a detailed SQL breakdown. The plugin supports multi-database configurations, smart SQL normalization to reduce false positives, and generates HTML reports with per-test query metrics. It is compatible with Python 3.10–3.14 and Django 4.0–6.0, and is available for installation via PyPI.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in