Skip to main content

A library designed to workaround some drawbacks with Django's union, intersection, and difference operations.

Project description

django-delayed-union is library designed to workaround some drawbacks with Django’s union, intersection, and difference operations. In particular, once one of these operations is performed, certain methods on the queryset will silently not work:

>>> qs = User.objects.filter(id=1)
>>> unioned_qs = qs.union(qs)
>>> should_be_empty_qs = unioned_qs.exclude(id=1)
>>> user, = list(should_be_empty_qs); user.id
1

In order to work around this, django-delayed-union provides wrappers around a collection of querysets. These wrappers implement a similar interface to QuerySet, and delay performing the union, intersection, or difference operations until they are needed:

>>> from django_delayed_union import DelayedUnionQuerySet
>>> qs = User.objects.filter(id=1)
>>> unioned_qs = DelayedUnionQuerySet(qs, qs)
>>> empty_qs = unioned_qs.exclude(id=1)
>>> list(empty_qs)
[]

Operations which would typically return a new QuerySet instead return a new DelayedQuerySet with the operation applied to its collection of querysets.

One example of where this code has been useful with is when the the MySQL query planner has chosen an inefficient query plan for the queryset of a Django REST Framework view which used an OR condition. By using DelayedUnionQuerySet, subclasses could perform additional filters on the queryset while still maintaining the efficient query plan.

  • Free software: BSD 3-Clause License

Installation

pip install django-delayed-union

Documentation

https://django-delayed-union.readthedocs.io/

Development

To run the all tests run:

tox

Changelog

0.1.7 (2022-01-12)

  • Fixed setup.py metadata

0.1.6 (2022-01-12)

  • Added support for Django 3.2 and 4.0.

  • Dropped Python 2 support.

0.1.5 (2020-04-14)

  • Added support for Python 3.8 and Django 3.0

0.1.4 (2019-10-19)

  • Added query property to delayed querysets.

  • Fixed bug with count() and select_related() in MySQL

  • Added tests for Django 3.0

0.1.3 (2019-04-24)

  • Added tests for Django 2.2

0.1.2 (2018-12-14)

  • Added support for nested unions and intersections

0.1.1 (2018-07-16)

  • Cached the queryset generated after applying the delayed operation.

0.1.0 (2018-03-14)

  • First release on PyPI.

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-delayed-union-0.1.7.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

django_delayed_union-0.1.7-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-delayed-union-0.1.7.tar.gz.

File metadata

  • Download URL: django-delayed-union-0.1.7.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11

File hashes

Hashes for django-delayed-union-0.1.7.tar.gz
Algorithm Hash digest
SHA256 50ae4848948f00785445c37801421bd82473cc699df39e10a031e34ad4d51e8d
MD5 20acf8e09e7656d85d6415c779851f5c
BLAKE2b-256 c2a889b9e6e149f857bccecb530bd7787ed94d85df730c882265fc166f8d4d28

See more details on using hashes here.

File details

Details for the file django_delayed_union-0.1.7-py2.py3-none-any.whl.

File metadata

  • Download URL: django_delayed_union-0.1.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.11

File hashes

Hashes for django_delayed_union-0.1.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 95bceff702508d79e4de6de7d44da32af7848eb96e140cece3abbe3c18d3a91a
MD5 74f9361e7e03be9f8093c47b38e7e83a
BLAKE2b-256 18c38c220f327f0d19a38e82f97d75549d6df82db18b26f0a5e0810c3b0d4ad4

See more details on using hashes here.

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