[PATCH 08/10] Add support for django-filter 1.1

Daniel Axtens dja at axtens.net
Tue Apr 30 16:03:06 AEST 2019


From: Stephen Finucane <stephen at that.guru>

There's one warning to handle here.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Signed-off-by: Daniel Axtens <dja at axtens.net>
(cherry picked from commit 4ad2558f884bf33201e179a171ad3821a62126a1)
Signed-off-by: Daniel Axtens <dja at axtens.net>
---
 README.rst                                       |  2 +-
 patchwork/api/filters.py                         |  5 +++--
 patchwork/compat.py                              | 16 ++++++++++++++++
 .../django-filter-1-1-6a6b0ab8cbe0faca.yaml      |  6 ++++++
 requirements-dev.txt                             |  2 +-
 requirements-prod.txt                            |  2 +-
 tox.ini                                          |  3 ++-
 7 files changed, 30 insertions(+), 6 deletions(-)
 create mode 100644 releasenotes/notes/django-filter-1-1-6a6b0ab8cbe0faca.yaml

diff --git a/README.rst b/README.rst
index ddc4b98125d1..94ac32c3b8b7 100644
--- a/README.rst
+++ b/README.rst
@@ -47,7 +47,7 @@ Requirements
 
 - Django REST Framework (3.4 - 3.8)
 
-- Django Filters (1.0)
+- Django Filters (1.0 - 1.1)
 
 Development Installation
 ------------------------
diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py
index 73353d900a94..ddf527fd837b 100644
--- a/patchwork/api/filters.py
+++ b/patchwork/api/filters.py
@@ -26,6 +26,7 @@ from django_filters import ModelMultipleChoiceFilter
 from django.forms import ModelMultipleChoiceField as BaseMultipleChoiceField
 from django.forms.widgets import MultipleHiddenInput
 
+from patchwork.compat import NAME_FIELD
 from patchwork.models import Bundle
 from patchwork.models import Check
 from patchwork.models import CoverLetter
@@ -151,8 +152,8 @@ class UserFilter(ModelMultipleChoiceFilter):
 class TimestampMixin(FilterSet):
 
     # TODO(stephenfin): These should filter on a 'updated_at' field instead
-    before = IsoDateTimeFilter(name='date', lookup_expr='lt')
-    since = IsoDateTimeFilter(name='date', lookup_expr='gte')
+    before = IsoDateTimeFilter(lookup_expr='lt', **{NAME_FIELD: 'date'})
+    since = IsoDateTimeFilter(lookup_expr='gte', **{NAME_FIELD: 'date'})
 
 
 class SeriesFilterSet(TimestampMixin, FilterSet):
diff --git a/patchwork/compat.py b/patchwork/compat.py
index 38caa4e861cf..3bbff447dbcb 100644
--- a/patchwork/compat.py
+++ b/patchwork/compat.py
@@ -41,6 +41,22 @@ if settings.ENABLE_REST_API:
         from rest_framework.filters import DjangoFilterBackend  # noqa
 
 
+# NAME_FIELD
+#
+# The django-filter library renamed 'Filter.name' to 'Filter.field_name' in
+# 1.1.
+#
+# https://django-filter.readthedocs.io/en/master/guide/migration.html#migrating-to-2-0
+
+if settings.ENABLE_REST_API:
+    import django_filters  # noqa
+
+    if django_filters.VERSION >= (1, 1):
+        NAME_FIELD = 'field_name'
+    else:
+        NAME_FIELD = 'name'
+
+
 # reverse, reverse_lazy
 #
 # The reverse and reverse_lazy functions have been moved to django.urls in
diff --git a/releasenotes/notes/django-filter-1-1-6a6b0ab8cbe0faca.yaml b/releasenotes/notes/django-filter-1-1-6a6b0ab8cbe0faca.yaml
new file mode 100644
index 000000000000..3beb9c0848ef
--- /dev/null
+++ b/releasenotes/notes/django-filter-1-1-6a6b0ab8cbe0faca.yaml
@@ -0,0 +1,6 @@
+---
+upgrade:
+  - |
+    `django-filter 1.1
+    <https://github.com/carltongibson/django-filter/releases/tag/1.1.0>`_ is
+    now supported.
diff --git a/requirements-dev.txt b/requirements-dev.txt
index b12246dd1b89..1d58df714290 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,4 +1,4 @@
 Django>=1.8,<2.0
 djangorestframework>=3.4,<3.9
-django-filter>=1.0,<1.1
+django-filter>=1.0,<1.2
 -r requirements-test.txt
diff --git a/requirements-prod.txt b/requirements-prod.txt
index 42ff8ecd82f1..59e2c1e6ce53 100644
--- a/requirements-prod.txt
+++ b/requirements-prod.txt
@@ -1,5 +1,5 @@
 Django>=1.8,<2.0
 djangorestframework>=3.4,<3.9
-django-filter>=1.0,<1.1
+django-filter>=1.0,<1.2
 psycopg2>=2.7,<2.8
 sqlparse==0.2.4
diff --git a/tox.ini b/tox.ini
index 5c741d374a64..c242c97f4d8b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -13,7 +13,8 @@ deps =
     django{18,19}: djangorestframework>=3.4,<3.7
     django110: djangorestframework>=3.4,<3.9
     django111: djangorestframework>=3.6,<3.9
-    django{18,19,110,111}: django-filter>=1.0,<1.1
+    django18: django-filter>=1.0,<1.1
+    django{19,110,111}: django-filter>=1.0,<1.2
 setenv =
     DJANGO_SETTINGS_MODULE = patchwork.settings.dev
     PYTHONDONTWRITEBYTECODE = 1
-- 
2.19.1



More information about the Patchwork mailing list