From patchwork Sat Oct 6 19:01:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 979987 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42SGGH680Mz9sBN for ; Sun, 7 Oct 2018 06:02:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="Kgifj8Cr"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42SGGG5rwFzF3KR for ; Sun, 7 Oct 2018 06:02:30 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="Kgifj8Cr"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.13; helo=relay013.mxrelay.co; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="Kgifj8Cr"; dkim-atps=neutral Received: from relay013.mxrelay.co (relay013.mxrelay.co [185.234.75.13]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42SGG556mNzF3LK for ; Sun, 7 Oct 2018 06:02:19 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay013.mxrelay.co (Postfix) with ESMTP id BC1EE42DDA for ; Sat, 6 Oct 2018 19:01:46 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id E8A073F0F4 for ; Sat, 6 Oct 2018 19:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=0Z8L0IhYnLFopqujg3Ed+Cqn0VVFh/pEElk3NLivBP0=; b=Kgifj8CrabduBr7cCWiiAsuRUU pZ3LJRdr6GLz2b+zUEEdRjEES5JJKdzPcWG6YUPwvyO3504YV5JO5J9ynqXv9NrdYi0K7x1Chaips WR3uft4uWnuUvUiIiwuki+M2AAvsf/k5bdS/RWxQvDBeY2oqyCCCxKmTWDUfOb8h1/aexFBrs9wqZ rJn8f2X6bkXB95sXTjTn+X1zyTZpUQWp93pfFG7wyn8amBJpYUM1Ss/u55PDrdJvhBSg1CoOaW2TJ rYIIU+rPDjcjVYgC9KCgHe8k7gUDYhSDCwOXrEXBJll0EN1v4qJpH8y5MeQW9bd826JMl2jfp6JID ZAVeAllg==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 2/4] Add support for django-filter 2.0 Date: Sat, 6 Oct 2018 20:01:36 +0100 Message-Id: <20181006190138.9798-2-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181006190138.9798-1-stephen@that.guru> References: <20181006190138.9798-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This is necessary for Django 2.1 support. We retain support for django-filter 1.0 and 1.1 as 2.0 is Python 3-only. Thankfully there is essentially zero cost in doing so for now. Signed-off-by: Stephen Finucane --- patchwork/api/bundle.py | 2 +- patchwork/api/check.py | 2 +- patchwork/api/cover.py | 2 +- patchwork/api/event.py | 2 +- patchwork/api/patch.py | 2 +- patchwork/api/series.py | 2 +- patchwork/compat.py | 20 +++++++++++++++++++ patchwork/settings/base.py | 2 +- .../django-filter-2-0-3240949516a873e3.yaml | 6 ++++++ requirements-dev.txt | 3 ++- requirements-prod.txt | 3 ++- tox.ini | 5 +++-- 12 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/django-filter-2-0-3240949516a873e3.yaml diff --git a/patchwork/api/bundle.py b/patchwork/api/bundle.py index 04045888..2dec70d1 100644 --- a/patchwork/api/bundle.py +++ b/patchwork/api/bundle.py @@ -66,7 +66,7 @@ class BundleMixin(object): class BundleList(BundleMixin, ListAPIView): """List bundles.""" - filter_class = BundleFilterSet + filter_class = filterset_class = BundleFilterSet search_fields = ('name',) ordering_fields = ('id', 'name', 'owner') ordering = 'id' diff --git a/patchwork/api/check.py b/patchwork/api/check.py index fbf05adb..48019e72 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -66,7 +66,7 @@ class CheckSerializer(HyperlinkedModelSerializer): class CheckMixin(object): serializer_class = CheckSerializer - filter_class = CheckFilterSet + filter_class = filterset_class = CheckFilterSet def get_queryset(self): patch_id = self.kwargs['patch_id'] diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py index d3d26bdf..40f8c351 100644 --- a/patchwork/api/cover.py +++ b/patchwork/api/cover.py @@ -83,7 +83,7 @@ class CoverLetterList(ListAPIView): """List cover letters.""" serializer_class = CoverLetterListSerializer - filter_class = CoverLetterFilterSet + filter_class = filterset_class = CoverLetterFilterSet search_fields = ('name',) ordering_fields = ('id', 'name', 'date', 'submitter') ordering = 'id' diff --git a/patchwork/api/event.py b/patchwork/api/event.py index 7fec6740..c0d973d8 100644 --- a/patchwork/api/event.py +++ b/patchwork/api/event.py @@ -75,7 +75,7 @@ class EventList(ListAPIView): """List events.""" serializer_class = EventSerializer - filter_class = EventFilterSet + filter_class = filterset_class = EventFilterSet page_size_query_param = None # fixed page size ordering_fields = () ordering = '-date' diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index f400c138..1e647283 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -153,7 +153,7 @@ class PatchList(ListAPIView): permission_classes = (PatchworkPermission,) serializer_class = PatchListSerializer - filter_class = PatchFilterSet + filter_class = filterset_class = PatchFilterSet search_fields = ('name',) ordering_fields = ('id', 'name', 'project', 'date', 'state', 'archived', 'submitter', 'check') diff --git a/patchwork/api/series.py b/patchwork/api/series.py index 5d4183b6..f7bb8c06 100644 --- a/patchwork/api/series.py +++ b/patchwork/api/series.py @@ -62,7 +62,7 @@ class SeriesMixin(object): class SeriesList(SeriesMixin, ListAPIView): """List series.""" - filter_class = SeriesFilterSet + filter_class = filterset_class = SeriesFilterSet search_fields = ('name',) ordering_fields = ('id', 'name', 'date', 'submitter', 'received_all') ordering = 'id' diff --git a/patchwork/compat.py b/patchwork/compat.py index 8fcb04cf..8d949607 100644 --- a/patchwork/compat.py +++ b/patchwork/compat.py @@ -13,12 +13,32 @@ from django.conf import settings # The django-filter library renamed 'Filter.name' to 'Filter.field_name' in # 1.1. # +# DjangoFilterBackend + +# The django-filter library changed the default strictness level in 2.0 +# # https://django-filter.readthedocs.io/en/master/guide/migration.html#migrating-to-2-0 if settings.ENABLE_REST_API: import django_filters # noqa + from django_filters import rest_framework # noqa + from rest_framework import exceptions # noqa if django_filters.VERSION >= (1, 1): NAME_FIELD = 'field_name' else: NAME_FIELD = 'name' + + if django_filters.VERSION >= (2, 0): + # TODO(stephenfin): Enable strict mode in API v2.0, possibly with a + # bump in the minimum version of django-filter [1] + # + # [1] https://github.com/carltongibson/django-filter/pull/983 + class DjangoFilterBackend(rest_framework.DjangoFilterBackend): + def filter_queryset(self, request, queryset, view): + try: + return super().filter_queryset(request, queryset, view) + except exceptions.ValidationError: + return queryset.none() + else: + DjangoFilterBackend = rest_framework.DjangoFilterBackend diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py index 1a62404f..c69947be 100644 --- a/patchwork/settings/base.py +++ b/patchwork/settings/base.py @@ -127,7 +127,7 @@ REST_FRAMEWORK = { 'rest_framework.versioning.URLPathVersioning', 'DEFAULT_PAGINATION_CLASS': 'patchwork.api.base.LinkHeaderPagination', 'DEFAULT_FILTER_BACKENDS': ( - 'django_filters.rest_framework.DjangoFilterBackend', + 'patchwork.compat.DjangoFilterBackend', 'rest_framework.filters.SearchFilter', 'rest_framework.filters.OrderingFilter', ), diff --git a/releasenotes/notes/django-filter-2-0-3240949516a873e3.yaml b/releasenotes/notes/django-filter-2-0-3240949516a873e3.yaml new file mode 100644 index 00000000..ee5e496c --- /dev/null +++ b/releasenotes/notes/django-filter-2-0-3240949516a873e3.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + `django-filter 2.0 + `_ is + now supported. This requires Python 3. diff --git a/requirements-dev.txt b/requirements-dev.txt index 70b747f5..2574fd37 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,6 @@ Django==2.0.8; python_version >= '3.4' Django==1.11.15; python_version < '3.0' djangorestframework==3.8.2 -django-filter==1.1.0 +django-filter==2.0.0; python_version >= '3.4' +django-filter==1.1.0; python_version < '3.0' # pyup: ignore -r requirements-test.txt diff --git a/requirements-prod.txt b/requirements-prod.txt index efe6743c..9b7cc6a2 100644 --- a/requirements-prod.txt +++ b/requirements-prod.txt @@ -1,6 +1,7 @@ Django==2.0.8; python_version >= '3.4' Django==1.11.15; python_version < '3.0' djangorestframework==3.8.2 -django-filter==1.1.0 +django-filter==2.0.0; python_version >= '3.4' +django-filter==1.1.0; python_version < '3.0' # pyup: ignore psycopg2-binary==2.7.5 sqlparse==0.2.4 diff --git a/tox.ini b/tox.ini index ab35be82..da2a5060 100644 --- a/tox.ini +++ b/tox.ini @@ -8,10 +8,11 @@ deps = -r{toxinidir}/requirements-test.txt django111: django>=1.11,<2.0 django111: djangorestframework>=3.6,<3.9 - django111: django-filter>=1.0,<1.2 + django111: django-filter>=1.0,<3.0; python_version >= '3.4' + django111: django-filter>=1.0,<2.0; python_version < '3.0' django20: django>=2.0,<2.1 django20: djangorestframework>=3.7,<3.9 - django20: django-filter>=1.1,<1.2 + django20: django-filter>=2.0,<3.0 setenv = DJANGO_SETTINGS_MODULE = patchwork.settings.dev PYTHONDONTWRITEBYTECODE = 1