Skip to content

Commit ebd5f31

Browse files
authored
Mini fix SerializerMethodField call to_representation method (#2)
* add __deepcopy__ on all serializers * v0.1.8
1 parent b5d753b commit ebd5f31

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

docs/release-notes.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Medium version numbers (0.x.0) may include API changes, in line with the [deprec
88

99
Major version numbers (x.0.0) are reserved for substantial project milestones.
1010

11+
### 0.1.8
12+
13+
**Date:** [23th March 2019]
14+
15+
* Mini fix [`SerializerMethodField`][SerializerMethodField] run `to_representation` method.
16+
1117
### 0.1.7
1218

1319
**Date:** [1st of January 2019]

rest_framework/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
__/ |
99
|___/
1010
"""
11-
VERSION = (0, 1, 7)
11+
VERSION = (0, 1, 8)
1212

1313
__title__ = 'Python-Rest-Framework'
1414
__author__ = 'Deys Timofey'

rest_framework/serializers/serializers.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import six
1515

16-
from rest_framework.serializers.fields import Field
16+
from rest_framework.serializers.fields import Field, SerializerMethodField
1717
from rest_framework.serializers.helpers import BindingDict
1818
from rest_framework.exceptions import SkipError
1919
from rest_framework.serializers.exceptions import ValidationError
@@ -314,12 +314,16 @@ def to_representation(self, instance):
314314
res = OrderedDict() # Attributes storage.
315315

316316
for field_name, field_val in six.iteritems(self.fields):
317-
# We try to get the attribute.
318-
try:
319-
attribute = field_val.get_attribute(instance)
320-
except SkipError:
321-
# TODO: That thing, throw an error, if the attribute of the object is not found, or skip?
322-
continue
317+
# TODO: mini hack
318+
if not isinstance(field_val, SerializerMethodField):
319+
# We try to get the attribute.
320+
try:
321+
attribute = field_val.get_attribute(instance)
322+
except SkipError:
323+
# TODO: That thing, throw an error, if the attribute of the object is not found, or skip?
324+
continue
325+
else:
326+
attribute = instance
323327

324328
# We try to turn it into a JSON valid format.
325329
res[field_name] = field_val.to_representation(attribute)

0 commit comments

Comments
 (0)