{"id":21172,"library":"django-zen-queries","title":"django-zen-queries","description":"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.","status":"active","version":"2.1.0","language":"python","source_language":"en","source_url":"https://github.com/dabapps/django-zen-queries","tags":["django","database","queries","performance","testing"],"install":[{"cmd":"pip install django-zen-queries","lang":"bash","label":"Standard install"}],"dependencies":[{"reason":"Requires Django >=2.0 for database instrumentation API","package":"Django","optional":false}],"imports":[{"note":"Most common import style is to import the module and use zen_queries.queries_disabled() etc.","wrong":"from zen_queries import ...","symbol":"zen_queries","correct":"import zen_queries"},{"note":"Use fetch() to force execution of a queryset within a disabled block.","wrong":"from django.db import connections; ...","symbol":"fetch","correct":"from zen_queries import fetch"}],"quickstart":{"code":"import zen_queries\nfrom django.db import connection\n\nwith zen_queries.queries_disabled():\n    # Any query executed here will raise an error\n    # pass\n\n# Or use as a decorator on a function\n@zen_queries.queries_disabled()\ndef my_view(request):\n    # Queries disabled inside\n    pass","lang":"python","description":"Basic usage: context manager or decorator to disable queries, raising an error if any query is attempted."},"warnings":[{"fix":"Upgrade to Django 2.0+ and django-zen-queries 2.0.0+.","message":"Version 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.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Use zen_queries.TemplateResponse instead of Django's TemplateResponse in class-based views, or evaluate permissions outside templates.","message":"Template 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Wrap template rendering with {% queries_disabled %} in templates or use zen_queries.TemplateResponse.","message":"The 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.","severity":"gotcha","affected_versions":">=2.1.0"}],"env_vars":null,"search_vec":"'2.0':29 '2.1.0':23 '3.6':26 'accident':15 'activ':30 'code':20 'control':10 'current':21 'databas':16,36 'django':2,6,28,35 'django-zen-queri':1 'execut':13 'explicit':9 'librari':7 'maintain':31 'minor':33 'perform':38 'prevent':14 'product':19 'python':25 'queri':4,12,17,37 'releas':34 'requir':24 'test':39 'version':22 'zen':3","created_at":"2026-04-27T16:58:27.812300+00:00","updated_at":"2026-04-27T16:58:27.812300+00:00","problems":[{"fix":"Identify the query and either move it outside the context or use `fetch()` to explicitly allow a prefetch or specific query.","cause":"A database query was executed inside a `queries_disabled()` context.","error":"AssertionError: Database queries disabled inside a queries_disabled context"},{"fix":"Ensure you have installed django-zen-queries 1.0+ and use `zen_queries.queries_disabled()`.","cause":"Using an older version (pre-1.0?) or incorrect import; the API was renamed.","error":"AttributeError: module 'zen_queries' has no attribute 'queries_disabled'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.1.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/dabapps/django-zen-queries","docs":null,"changelog":"https://github.com/dabapps/django-zen-queries/releases","pypi":"https://pypi.org/project/django-zen-queries/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}