django-seal
===========
.. image:: https://publicdomainvectors.org/photos/Seal2.png
:target: https://publicdomainvectors.org
:alt: Seal
------------
.. image:: https://github.com/charettes/django-seal/workflows/Test/badge.svg
:target: https://github.com/charettes/django-seal/actions
:alt: Build Status
.. image:: https://coveralls.io/repos/github/charettes/django-seal/badge.svg?branch=master
:target: https://coveralls.io/github/charettes/django-seal?branch=master
:alt: Coverage status
Django application providing queryset sealing capability to force appropriate usage of ``only()``/``defer()`` and
``select_related()``/``prefetch_related()``.
Installation
------------
.. code:: sh
pip install django-seal
Usage
-----
.. code:: python
# models.py
from django.db import models
from seal.models import SealableModel
class Location(SealableModel):
latitude = models.FloatField()
longitude = models.FloatField()
class SeaLion(SealableModel):
height = models.PositiveIntegerField()
weight = models.PositiveIntegerField()
location = models.ForeignKey(Location, models.CASCADE, null=True)
previous_locations = models.ManyToManyField(Location, related_name='previous_visitors')
By default ``UnsealedAttributeAccess`` warnings will be raised on sealed objects attributes accesses
.. code:: python
>>> location = Location.objects.create(latitude=51.585474, longitude=156.634331)
>>> sealion = SeaLion.objects.create(height=1, weight=100, location=location)
>>> sealion.previous_locations.add(location)
>>> SeaLion.objects.only('height').seal().get().weight
UnsealedAttributeAccess:: Attempt to fetch deferred field "weight" on sealed <SeaLion instance>.
>>> SeaLion.objects.seal().get().location
UnsealedAttributeAccess: Attempt to fetch related field "location" on sealed <SeaLion instance>.
>>> SeaLion.objects.seal().get().previous_locations.all()
UnsealedAttributeAccess: Attempt to fetch many-to-many field "previous_locations" on sealed <SeaLion instance>.
You can `elevate the warnings to exceptions by filtering them`_. This is useful to assert no unsealed attribute accesses are
performed when running your test suite for example.
.. code:: python
>>> import warnings
>>> from seal.exceptions import UnsealedAttributeAccess
>>> warnings.filterwarnings('error', category=UnsealedAttributeAccess)
>>> SeaLion.objects.only('height').seal().get().weight
Traceback (most recent call last)
...
UnsealedAttributeAccess:: Attempt to fetch deferred field "weight" on sealed <SeaLion instance>.
>>> SeaLion.objects.seal().get().location
Traceback (most recent call last)
...
UnsealedAttributeAccess: Attempt to fetch related field "location" on sealed <SeaLion instance>.
>>> SeaLion.objects.seal().get().previous_locations.all()
Traceback (most recent call last)
...
UnsealedAttributeAccess: Attempt to fetch many-to-many field "previous_locations" on sealed <SeaLion instance>.
Or you can `configure logging to capture warnings`_ to log unsealed attribute accesses to the ``py.warnings`` logger which is a
nice way to identify and address unsealed attributes accesses from production logs without taking your application down if some
instances happen to slip through your battery of tests.
.. code:: python
>>> import logging
>>> logging.captureWarnings(True)
.. _elevate the warnings to exceptions by filtering them: https://docs.python.org/3/library/warnings.html#warnings.filterwarnings
.. _configure logging to capture warnings: https://docs.python.org/3/library/logging.html#logging.captureWarnings
Sealable managers can also be automatically sealed at model definition time to avoid having to call ``seal()`` systematically
by passing ``seal=True`` to ``SealableModel`` subclasses, ``SealableManager`` and ``SealableQuerySet.as_manager``.
.. code-block:: python
from django.db import models
from seal.models import SealableManager, SealableModel, SealableQuerySet
class Location(SealableModel, seal=True):
latitude = models.FloatField()
longitude = models.FloatField()
class SeaLion(SealableModel):
height = models.PositiveIntegerField()
weight = models.PositiveIntegerField()
location = models.ForeignKey(Location, models.CASCADE, null=True)
previous_locations = models.ManyToManyField(Location, related_name='previous_visitors')
objects = SealableManager(seal=True)
others = SealableQuerySet.as_manager(seal=True)
Development
-----------
Make your changes, and then run tests via tox:
.. code:: sh
tox
Raw data
{
"_id": null,
"home_page": "https://github.com/charettes/django-seal",
"name": "django-seal",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Simon Charette",
"author_email": "simon.charette@zapier.com",
"download_url": "https://files.pythonhosted.org/packages/d5/7a/e0f3e99609ba55752d478555713df6e5f0e2bb7a30b3e0bd97bec879f1d3/django_seal-1.6.3.tar.gz",
"platform": null,
"description": "django-seal\n===========\n\n.. image:: https://publicdomainvectors.org/photos/Seal2.png\n :target: https://publicdomainvectors.org\n :alt: Seal\n\n------------\n\n.. image:: https://github.com/charettes/django-seal/workflows/Test/badge.svg\n :target: https://github.com/charettes/django-seal/actions\n :alt: Build Status\n\n.. image:: https://coveralls.io/repos/github/charettes/django-seal/badge.svg?branch=master\n :target: https://coveralls.io/github/charettes/django-seal?branch=master\n :alt: Coverage status\n\n\nDjango application providing queryset sealing capability to force appropriate usage of ``only()``/``defer()`` and\n``select_related()``/``prefetch_related()``.\n\nInstallation\n------------\n\n.. code:: sh\n\n pip install django-seal\n\nUsage\n-----\n\n.. code:: python\n\n # models.py\n from django.db import models\n from seal.models import SealableModel\n\n class Location(SealableModel):\n latitude = models.FloatField()\n longitude = models.FloatField()\n\n class SeaLion(SealableModel):\n height = models.PositiveIntegerField()\n weight = models.PositiveIntegerField()\n location = models.ForeignKey(Location, models.CASCADE, null=True)\n previous_locations = models.ManyToManyField(Location, related_name='previous_visitors')\n\nBy default ``UnsealedAttributeAccess`` warnings will be raised on sealed objects attributes accesses\n\n.. code:: python\n\n >>> location = Location.objects.create(latitude=51.585474, longitude=156.634331)\n >>> sealion = SeaLion.objects.create(height=1, weight=100, location=location)\n >>> sealion.previous_locations.add(location)\n >>> SeaLion.objects.only('height').seal().get().weight\n UnsealedAttributeAccess:: Attempt to fetch deferred field \"weight\" on sealed <SeaLion instance>.\n >>> SeaLion.objects.seal().get().location\n UnsealedAttributeAccess: Attempt to fetch related field \"location\" on sealed <SeaLion instance>.\n >>> SeaLion.objects.seal().get().previous_locations.all()\n UnsealedAttributeAccess: Attempt to fetch many-to-many field \"previous_locations\" on sealed <SeaLion instance>.\n\nYou can `elevate the warnings to exceptions by filtering them`_. This is useful to assert no unsealed attribute accesses are\nperformed when running your test suite for example.\n\n.. code:: python\n\n >>> import warnings\n >>> from seal.exceptions import UnsealedAttributeAccess\n >>> warnings.filterwarnings('error', category=UnsealedAttributeAccess)\n >>> SeaLion.objects.only('height').seal().get().weight\n Traceback (most recent call last)\n ...\n UnsealedAttributeAccess:: Attempt to fetch deferred field \"weight\" on sealed <SeaLion instance>.\n >>> SeaLion.objects.seal().get().location\n Traceback (most recent call last)\n ...\n UnsealedAttributeAccess: Attempt to fetch related field \"location\" on sealed <SeaLion instance>.\n >>> SeaLion.objects.seal().get().previous_locations.all()\n Traceback (most recent call last)\n ...\n UnsealedAttributeAccess: Attempt to fetch many-to-many field \"previous_locations\" on sealed <SeaLion instance>.\n\nOr you can `configure logging to capture warnings`_ to log unsealed attribute accesses to the ``py.warnings`` logger which is a\nnice way to identify and address unsealed attributes accesses from production logs without taking your application down if some\ninstances happen to slip through your battery of tests.\n\n.. code:: python\n\n >>> import logging\n >>> logging.captureWarnings(True)\n\n.. _elevate the warnings to exceptions by filtering them: https://docs.python.org/3/library/warnings.html#warnings.filterwarnings\n.. _configure logging to capture warnings: https://docs.python.org/3/library/logging.html#logging.captureWarnings\n\nSealable managers can also be automatically sealed at model definition time to avoid having to call ``seal()`` systematically\nby passing ``seal=True`` to ``SealableModel`` subclasses, ``SealableManager`` and ``SealableQuerySet.as_manager``.\n\n.. code-block:: python\n\n from django.db import models\n from seal.models import SealableManager, SealableModel, SealableQuerySet\n\n class Location(SealableModel, seal=True):\n latitude = models.FloatField()\n longitude = models.FloatField()\n\n class SeaLion(SealableModel):\n height = models.PositiveIntegerField()\n weight = models.PositiveIntegerField()\n location = models.ForeignKey(Location, models.CASCADE, null=True)\n previous_locations = models.ManyToManyField(Location, related_name='previous_visitors')\n\n objects = SealableManager(seal=True)\n others = SealableQuerySet.as_manager(seal=True)\n\nDevelopment\n-----------\n\nMake your changes, and then run tests via tox:\n\n.. code:: sh\n\n tox\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Allows ORM constructs to be sealed to prevent them from executing queries on attribute accesses.",
"version": "1.6.3",
"project_urls": {
"Homepage": "https://github.com/charettes/django-seal"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "13c23b8bfc828c3bfaeb9ac62c432391cca195e0358da5eddb52437a33119cdb",
"md5": "d49712859ac42b7f1cb4199474207eb3",
"sha256": "236df5cce4ad1eb8d142067a9998e92319746c337e78e4f9a947f7601ad5cffb"
},
"downloads": -1,
"filename": "django_seal-1.6.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "d49712859ac42b7f1cb4199474207eb3",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 9290,
"upload_time": "2024-09-05T12:38:13",
"upload_time_iso_8601": "2024-09-05T12:38:13.407956Z",
"url": "https://files.pythonhosted.org/packages/13/c2/3b8bfc828c3bfaeb9ac62c432391cca195e0358da5eddb52437a33119cdb/django_seal-1.6.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d57ae0f3e99609ba55752d478555713df6e5f0e2bb7a30b3e0bd97bec879f1d3",
"md5": "030a5d779e0bcc68fb25e2e16891415f",
"sha256": "7feb7d5724564b24efea919667837bc9647ae3a0fa55ad7d585cd063f1cc2cfb"
},
"downloads": -1,
"filename": "django_seal-1.6.3.tar.gz",
"has_sig": false,
"md5_digest": "030a5d779e0bcc68fb25e2e16891415f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12964,
"upload_time": "2024-09-05T12:38:15",
"upload_time_iso_8601": "2024-09-05T12:38:15.070359Z",
"url": "https://files.pythonhosted.org/packages/d5/7a/e0f3e99609ba55752d478555713df6e5f0e2bb7a30b3e0bd97bec879f1d3/django_seal-1.6.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-05 12:38:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "charettes",
"github_project": "django-seal",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-seal"
}