Skip to main content

Blocks any DB query from being executed within the context.

Project description

django-query-blocker

Prevents django to perform any query within the context or decorated method

Table of Contents

  1. Why Should I Use This?
  2. How To Install
  3. How To Use
    1. Context
    2. Decorator

Why Should I Use This?

Django ORM is great and easy to use but can easily hide some very back behaviours. Just by calling a property here and there you can cascade a chain of hundreds of queries hidden behind the easy-to-use model abstractions. This lib prevents it to happen by locking the ORM not allowing it to perform the queries by raising an exception.

How To Install

  • Install with
pip install django-query-blocker

How To Use

  • It can be used as a context or decorator

Context

from query_blocker import block_extra_queries

my_object = MyModel.objects.first()
print(my_object)  # works fine
with block_extra_queries:
    print(obj.foreign_key_obj) # will raise a NoExtraQueryException

Decorator

from query_blocker import block_extra_queries

@block_extra_queries
def my_method(obj):
    print(obj.foreign_key_obj)

my_object = MyModel.objects.first()
print(my_object)  # works fine
my_method(my_object)  # will raise a NoExtraQueryException

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-query-blocker-0.0.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

django_query_blocker-0.0.1-py2.py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page