Skip to content

Commit ae95d17

Browse files
author
nxexox
committed
fix nested serializers
1 parent 5175baf commit ae95d17

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

docs/release-notes.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ Medium version numbers (0.x.0) may include API changes, in line with the [deprec
99
Major version numbers (x.0.0) are reserved for substantial project milestones.
1010

1111

12+
### 0.3.14
13+
14+
**Date:** [18th June 2019]
15+
16+
* Fix required nested serializers
17+
1218
### 0.3.13
1319

1420
**Date:** [2nd April 2020]
1521

1622
* Added check on `None` in `to_representation` methods in:
17-
* ['CharField'][CharField]
18-
* ['IntegerField'][IntegerField]
19-
* ['FloatField'][FloatField]
20-
* ['DictField'][DictField]
23+
* [`CharField`][CharField]
24+
* [`IntegerField`][IntegerField]
25+
* [`FloatField`][FloatField]
26+
* [`DictField`][DictField]
2127

2228
### 0.3.12
2329

rest_framework/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
__/ |
99
|___/
1010
"""
11-
VERSION = (0, 3, 13)
11+
VERSION = (0, 3, 14)
1212

1313
__title__ = 'Python-Rest-Framework'
1414
__author__ = 'Deys Timofey'
1515
__email__ = '[email protected]'
16-
__copyright__ = 'Copyright (c) 2019 Deys Timofey'
16+
__copyright__ = 'Copyright (c) 2020 Deys Timofey'
1717
__license__ = 'Apache License 2.0'
1818
__url__ = 'https://github.com/nxexox/python-rest-framework'
1919
__version__ = '.'.join(map(str, VERSION))

rest_framework/serializers/serializers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def __new__(cls, *args, **kwargs):
131131
return super(BaseSerializer, cls).__new__(cls)
132132

133133
def __deepcopy__(self, memo={}):
134-
return self.__class__(instance=self.instance, data=self.data, source=self.source, allow_none=self.allow_none)
134+
return self.__class__(instance=self.instance, data=self.data,
135+
source=self.source, allow_none=self.allow_none,
136+
required=self.required)
135137

136138
@classmethod
137139
def many_init(cls, *args, **kwargs):
@@ -384,8 +386,15 @@ def _field_validation(self, fields_dict, data):
384386
for _, field_obj in six.iteritems(fields_dict):
385387
field_name = field_obj._get_field_name()
386388
try:
389+
# Check by empty for nested serializer fields
390+
is_empty, _field_data = field_obj.validate_empty_values(data.get(field_name, None))
391+
if is_empty:
392+
if field_name in data:
393+
validated_data[field_name] = _field_data
394+
continue
395+
387396
# Transform to python type and validate each field.
388-
validated_val = field_obj.run_validation(data.get(field_name, None))
397+
validated_val = field_obj.run_validation(_field_data)
389398

390399
# Now manual validation.
391400
validated_val = self._manual_validate_method(field_name, validated_val)
@@ -538,7 +547,8 @@ def __deepcopy__(self, memo={}):
538547
return self.__class__(
539548
instance=self.instance, data=self.data,
540549
child=self.child, allow_empty=self.allow_empty,
541-
source=self.source, allow_none=self.allow_none
550+
source=self.source, allow_none=self.allow_none,
551+
required=self.required
542552
)
543553

544554
def to_internal_value(self, data):

0 commit comments

Comments
 (0)