From 8926754c52eb214354625da7c7fb7f0fcfe31941 Mon Sep 17 00:00:00 2001 From: Matt Layman Date: Wed, 17 May 2017 08:48:58 -0400 Subject: [PATCH 1/2] Fix tests to work with DRF 3.6.3. Fixes #350 --- AUTHORS | 5 +++-- example/serializers.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 78ce1bb2..bc8d6dee 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,7 @@ -Jerel Unruh -Greg Aker Adam Wróbel Christian Zosel +Greg Aker +Jerel Unruh +Matt Layman Oliver Sauder diff --git a/example/serializers.py b/example/serializers.py index e8ee53ca..a3409731 100644 --- a/example/serializers.py +++ b/example/serializers.py @@ -37,12 +37,12 @@ class Meta: class EntrySerializer(serializers.ModelSerializer): def __init__(self, *args, **kwargs): + super(EntrySerializer, self).__init__(*args, **kwargs) # to make testing more concise we'll only output the # `featured` field when it's requested via `include` request = kwargs.get('context', {}).get('request') if request and 'featured' not in request.query_params.get('include', []): self.fields.pop('featured') - super(EntrySerializer, self).__init__(*args, **kwargs) included_serializers = { 'authors': 'example.serializers.AuthorSerializer', From ff98a395153252b9478bf807e6ab6934e97fe7e9 Mon Sep 17 00:00:00 2001 From: Matt Layman Date: Wed, 17 May 2017 09:28:46 -0400 Subject: [PATCH 2/2] Avoid raising a KeyError. This test checked a condition that created a RuntimeError in the past. In this newer version of DRF, the field is not included so the key should be ignored when not present. --- example/serializers.py | 2 +- rest_framework_json_api/serializers.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/example/serializers.py b/example/serializers.py index a3409731..0dfc49b4 100644 --- a/example/serializers.py +++ b/example/serializers.py @@ -42,7 +42,7 @@ def __init__(self, *args, **kwargs): # `featured` field when it's requested via `include` request = kwargs.get('context', {}).get('request') if request and 'featured' not in request.query_params.get('include', []): - self.fields.pop('featured') + self.fields.pop('featured', None) included_serializers = { 'authors': 'example.serializers.AuthorSerializer', diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py index 32ffb385..b2a69c9d 100644 --- a/rest_framework_json_api/serializers.py +++ b/rest_framework_json_api/serializers.py @@ -50,6 +50,7 @@ def to_internal_value(self, data): class SparseFieldsetsMixin(object): def __init__(self, *args, **kwargs): + super(SparseFieldsetsMixin, self).__init__(*args, **kwargs) context = kwargs.get('context') request = context.get('request') if context else None @@ -74,8 +75,6 @@ def __init__(self, *args, **kwargs): if field_name not in fieldset: self.fields.pop(field_name) - super(SparseFieldsetsMixin, self).__init__(*args, **kwargs) - class IncludedResourcesValidationMixin(object): def __init__(self, *args, **kwargs):