From b5edd0c77fc4698c0f546646ee1c8a87df08d2ba Mon Sep 17 00:00:00 2001 From: Nikita Daianov Date: Tue, 29 Apr 2025 17:21:07 +0200 Subject: [PATCH 1/5] DRF 3.16.x support --- .github/workflows/django.yml | 2 +- README.md | 4 ++-- README.rst | 2 +- dynamic_rest/__init__.py | 3 ++- install_requires.txt | 2 +- requirements.txt | 2 +- setup.py | 3 ++- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 09a244fa..f2737fc1 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -14,7 +14,7 @@ jobs: matrix: python-version: [3.9, "3.10", "3.11", "3.12"] dj-version: ["3.0.*", "3.1.*", "3.2.*", "4.0.*", "4.1.*", "4.2.*", "5.0.*", "5.1.*"] - drf-version: ["3.11.*", "3.12.*", "3.13.*", "3.14.*", "3.15.*"] + drf-version: ["3.11.*", "3.12.*", "3.13.*", "3.14.*", "3.15.*", "3.16.*"] exclude: - dj-version: '4.0.*' drf-version: '3.11.*' diff --git a/README.md b/README.md index 531f8484..84c389ee 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ over HTTP. - Python (3.9, 3.10, 3.11, 3.12) - Django (3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1) -- Django REST Framework (3.11, 3.12, 3.13, 3.14, 3.15) +- Django REST Framework (3.11, 3.12, 3.13, 3.14, 3.15, 3.16) # Installation @@ -649,7 +649,7 @@ We actively support the following: - Python: 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 - Django: 2.2, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1 -- Django Rest Framework: 3.11, 3.12, 3.13, 3.14, 3.15 +- Django Rest Framework: 3.11, 3.12, 3.13, 3.14, 3.15, 3.16 **Note:** Some combinations are not supported. For up-to-date information on actively supported/tested combinations, see the `tox.ini` file. diff --git a/README.rst b/README.rst index a54ab4de..9d6acf16 100644 --- a/README.rst +++ b/README.rst @@ -46,4 +46,4 @@ Requirements - Python (3.9, 3.10, 3.11, 3.12) - Django (3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1) -- Django REST Framework (3.11, 3.12, 3.13, 3.14, 3.15) +- Django REST Framework (3.11, 3.12, 3.13, 3.14, 3.15, 3.16) diff --git a/dynamic_rest/__init__.py b/dynamic_rest/__init__.py index 49959bdc..ba5dbade 100644 --- a/dynamic_rest/__init__.py +++ b/dynamic_rest/__init__.py @@ -8,5 +8,6 @@ - Directory panel for the browsable API - Optimizations """ -__version__ = "2.5.1" + +__version__ = "2.5.2" default_app_config = "dynamic_rest.apps.DynamicRestConfig" diff --git a/install_requires.txt b/install_requires.txt index c9af0dd4..72738916 100644 --- a/install_requires.txt +++ b/install_requires.txt @@ -1,5 +1,5 @@ Django>=3.2,<5.2 -djangorestframework>=3.11.2,<3.16 +djangorestframework>=3.11.2,<3.17 inflection>=0.5.0 requests sqids>=0.1.0 diff --git a/requirements.txt b/requirements.txt index 97d94c4f..4d7b27ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ tox==4.11.3 twine==4.0.2 inflection==0.5.1 Django>=3.2,<5.2 -djangorestframework>=3.11.2,<3.16 +djangorestframework>=3.11.2,<3.17 orjson>=3.9.7 black==23.9.1 isort==5.12.0 diff --git a/setup.py b/setup.py index 895e7ffa..87bc607c 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,11 @@ """Setup script for dynamic-rest-bse.""" + from setuptools import find_packages, setup NAME = "dynamic-rest-bse" DESCRIPTION = "Dynamic API support to Django REST Framework. Forked..." URL = "http://github.com/BillSchumacher/dynamic-rest" -VERSION = "2.5.1" +VERSION = "2.5.2" SCRIPTS = ["manage.py"] with open("install_requires.txt", encoding="utf-8") as fp: From f72034d9c0ff4bd920239ed27f9f9dca99de5e24 Mon Sep 17 00:00:00 2001 From: Nikita Daianov Date: Tue, 29 Apr 2025 18:02:41 +0200 Subject: [PATCH 2/5] Exclude django 3.0-4.1 version from test build matrix for DRF 3.16.x --- .github/workflows/django.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index f2737fc1..cba02588 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -48,6 +48,16 @@ jobs: drf-version: '3.12.*' - dj-version: '5.1.*' drf-version: '3.13.*' + - dj-version: '3.0.*' + drf-version: '3.16.*' + - dj-version: '3.1.*' + drf-version: '3.16.*' + - dj-version: '3.2.*' + drf-version: '3.16.*' + - dj-version: '4.0.*' + drf-version: '3.16.*' + - dj-version: '4.1.*' + drf-version: '3.16.*' - python-version: 3.12 dj-version: '3.0.*' - python-version: 3.12 From f75a303794a18b20c7680a8d314a87de3b4acc15 Mon Sep 17 00:00:00 2001 From: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Date: Wed, 30 Apr 2025 09:02:41 -0500 Subject: [PATCH 3/5] Add variable and disable building prefetches as well. --- dynamic_rest/filters/base.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/dynamic_rest/filters/base.py b/dynamic_rest/filters/base.py index 90d69e9f..ae063520 100644 --- a/dynamic_rest/filters/base.py +++ b/dynamic_rest/filters/base.py @@ -102,6 +102,7 @@ class DynamicFilterBackend(BaseFilterBackend): This backend is responsible for interpreting and applying filters, includes, and excludes to the base queryset of a view. """ + DISABLE_PREFETCHING = False def filter_queryset(self, request: Request, queryset: QuerySet, view) -> QuerySet: """Filter the queryset. @@ -119,7 +120,7 @@ def filter_queryset(self, request: Request, queryset: QuerySet, view) -> QuerySe # after this is called may not behave as expected extra_filters = self.view.get_extra_filters(request) - disable_prefetches = self.view.is_update() + disable_prefetches = self.view.is_update() or self.DISABLE_PREFETCHING return self._build_queryset( queryset=queryset, @@ -391,14 +392,14 @@ def _build_queryset( if filters is None: filters = _get_requested_filters(getattr(self, "view", None)) - # build nested Prefetch queryset - self._build_requested_prefetches( - prefetches, requirements, model, fields, filters - ) - - # build remaining prefetches out of internal requirements - # that are not already covered by request requirements - self._build_implicit_prefetches(model, prefetches, requirements) + if not disable_prefetches: + # build nested Prefetch queryset + self._build_requested_prefetches( + prefetches, requirements, model, fields, filters + ) + # build remaining prefetches out of internal requirements + # that are not already covered by request requirements + self._build_implicit_prefetches(model, prefetches, requirements) # use requirements at this level to limit fields selected # only do this for GET requests where we are not requesting the From b8250f7ccf8979a5385ae1f511356f70d45874c7 Mon Sep 17 00:00:00 2001 From: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Date: Mon, 5 May 2025 10:29:16 -0500 Subject: [PATCH 4/5] Add backend without prefetching, bump version. --- dynamic_rest/__init__.py | 2 +- dynamic_rest/filters/base.py | 8 ++++++++ setup.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dynamic_rest/__init__.py b/dynamic_rest/__init__.py index ba5dbade..d7e5bef3 100644 --- a/dynamic_rest/__init__.py +++ b/dynamic_rest/__init__.py @@ -9,5 +9,5 @@ - Optimizations """ -__version__ = "2.5.2" +__version__ = "2.5.3" default_app_config = "dynamic_rest.apps.DynamicRestConfig" diff --git a/dynamic_rest/filters/base.py b/dynamic_rest/filters/base.py index ae063520..c10997ac 100644 --- a/dynamic_rest/filters/base.py +++ b/dynamic_rest/filters/base.py @@ -462,3 +462,11 @@ def _build_queryset( if DEBUG: queryset._using_prefetches = prefetches # pylint: disable=protected-access return queryset + +class DynamicFilterNoPrefetchBackend(DynamicFilterBackend): + """A DRF filter backend that constructs DREST QuerySets without prefetching. + + This backend is responsible for interpreting and applying + filters, includes, and excludes to the base queryset of a view. + """ + DISABLE_PREFETCHING = True diff --git a/setup.py b/setup.py index 87bc607c..6c1bf30d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ NAME = "dynamic-rest-bse" DESCRIPTION = "Dynamic API support to Django REST Framework. Forked..." URL = "http://github.com/BillSchumacher/dynamic-rest" -VERSION = "2.5.2" +VERSION = "2.5.3" SCRIPTS = ["manage.py"] with open("install_requires.txt", encoding="utf-8") as fp: From 0e2c92b9b4716f8c7689d1cbb7a4c72505ec2587 Mon Sep 17 00:00:00 2001 From: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Date: Mon, 5 May 2025 10:30:44 -0500 Subject: [PATCH 5/5] Linting --- dynamic_rest/filters/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dynamic_rest/filters/base.py b/dynamic_rest/filters/base.py index c10997ac..b827819b 100644 --- a/dynamic_rest/filters/base.py +++ b/dynamic_rest/filters/base.py @@ -463,10 +463,13 @@ def _build_queryset( queryset._using_prefetches = prefetches # pylint: disable=protected-access return queryset + class DynamicFilterNoPrefetchBackend(DynamicFilterBackend): - """A DRF filter backend that constructs DREST QuerySets without prefetching. + """ + A DRF filter backend that constructs DREST QuerySets without prefetching. This backend is responsible for interpreting and applying filters, includes, and excludes to the base queryset of a view. """ + DISABLE_PREFETCHING = True