Registry / web-framework / django-zen-queries

django-zen-queries

JSON →
library2.1.0pypypi✓ verified 87d ago

A Django library for explicit control over query execution, preventing accidental database queries in production code. Current version 2.1.0, requires Python >=3.6 and Django >=2.0. Actively maintained with minor releases.

pip install django-zen-queries
INSTALL
IMPORT
SIG · DJANGO-ZEN-QUERIES
D
django-zen-queries
web-frameworkpythonv2.1.0
Install
3.4s avg
Import
657ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.692s · 66.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.4s · import 0.622s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

zen_queries
import zen_queries
from zen_queries import ...
Most common import style is to import the module and use zen_queries.queries_disabled() etc.
fetch
from zen_queries import fetch
from django.db import connections; ...
Use fetch() to force execution of a queryset within a disabled block.

Basic usage: context manager or decorator to disable queries, raising an error if any query is attempted.

import zen_queries from django.db import connection with zen_queries.queries_disabled(): # Any query executed here will raise an error # pass # Or use as a decorator on a function @zen_queries.queries_disabled() def my_view(request): # Queries disabled inside pass
Debug
Known issues
breakingVersion 2.0.0 changed the internal implementation from monkeypatching to Django's Database Instrumentation API. Requires Django >=2.0. Django <2.0 is no longer supported.
fix
Upgrade to Django 2.0+ and django-zen-queries 2.0.0+.
affects: <2.0.0
gotchaTemplate permission checks (e.g., {% if perms %}) may trigger database queries even inside a queries_disabled block, because they are evaluated during template rendering. This can cause unexpected errors.
fix
Use zen_queries.TemplateResponse instead of Django's TemplateResponse in class-based views, or evaluate permissions outside templates.
affects: all
gotchaThe context manager does not automatically disable queries in template rendering. Use zen_queries.TemplateResponse or the {% queries_disabled %} template tag (added in 2.1.0) to cover templates.
fix
Wrap template rendering with {% queries_disabled %} in templates or use zen_queries.TemplateResponse.
affects: >=2.1.0
Errors
Common errors & fixes
AssertionError: Database queries disabled inside a queries_disabled context
A database query was executed inside a `queries_disabled()` context.
fix
Identify the query and either move it outside the context or use `fetch()` to explicitly allow a prefetch or specific query.
AttributeError: module 'zen_queries' has no attribute 'queries_disabled'
Using an older version (pre-1.0?) or incorrect import; the API was renamed.
fix
Ensure you have installed django-zen-queries 1.0+ and use `zen_queries.queries_disabled()`.
Upgrade
Version history
2.1.0latest on PyPI · released Jul 27, 2021
Audit
Dependencies
DjangorequiredRequires Django >=2.0 for database instrumentation API
Agent activity
6 hits · last 30 days
node
6
Resources
django-zen-queries — pip install django-zen-queries · libregistry