Skip to content

Commit a12d98d

Browse files
authored
Fix tests to work with DRF 3.6.3. (#351)
* Fix tests to work with DRF 3.6.3. Fixes #350 * 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.
1 parent 485953f commit a12d98d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

AUTHORS

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Jerel Unruh <mail@unruhdesigns.com>
2-
Greg Aker <greg@gregaker.net>
31
Adam Wróbel <https://adamwrobel.com>
42
Christian Zosel <https://zosel.ch>
3+
Greg Aker <greg@gregaker.net>
4+
Jerel Unruh <mail@unruhdesigns.com>
5+
Matt Layman <http://www.mattlayman.com>
56
Oliver Sauder <os@esite.ch>
67

example/serializers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class Meta:
3737
class EntrySerializer(serializers.ModelSerializer):
3838

3939
def __init__(self, *args, **kwargs):
40+
super(EntrySerializer, self).__init__(*args, **kwargs)
4041
# to make testing more concise we'll only output the
4142
# `featured` field when it's requested via `include`
4243
request = kwargs.get('context', {}).get('request')
4344
if request and 'featured' not in request.query_params.get('include', []):
44-
self.fields.pop('featured')
45-
super(EntrySerializer, self).__init__(*args, **kwargs)
45+
self.fields.pop('featured', None)
4646

4747
included_serializers = {
4848
'authors': 'example.serializers.AuthorSerializer',

rest_framework_json_api/serializers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def to_internal_value(self, data):
5050

5151
class SparseFieldsetsMixin(object):
5252
def __init__(self, *args, **kwargs):
53+
super(SparseFieldsetsMixin, self).__init__(*args, **kwargs)
5354
context = kwargs.get('context')
5455
request = context.get('request') if context else None
5556

@@ -74,8 +75,6 @@ def __init__(self, *args, **kwargs):
7475
if field_name not in fieldset:
7576
self.fields.pop(field_name)
7677

77-
super(SparseFieldsetsMixin, self).__init__(*args, **kwargs)
78-
7978

8079
class IncludedResourcesValidationMixin(object):
8180
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)