Skip to content

Commit

Permalink
Fix Serializer exclude for declared fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan P Kilby committed Nov 15, 2017
1 parent 0b72285 commit 33d3bd9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rest_framework/serializers.py
Expand Up @@ -1099,6 +1099,9 @@ def get_field_names(self, declared_fields, info):
# Use the default set of field names if `Meta.fields` is not specified.
fields = self.get_default_field_names(declared_fields, info)

# deduplicate field names (occurs when a declared fields matches a model field)
fields = list(OrderedDict.fromkeys(fields))

if exclude is not None:
# If `Meta.exclude` is included, then remove those fields.
for field_name in exclude:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model_serializer.py
Expand Up @@ -908,7 +908,7 @@ class Meta:
model = MetaClassTestModel
exclude = ('text',)

assert list(ExampleSerializer().fields) == ['id', 'text']
assert list(ExampleSerializer().fields) == ['id']


class Issue2704TestCase(TestCase):
Expand Down

0 comments on commit 33d3bd9

Please sign in to comment.