@@ -1626,14 +1626,28 @@ def to_internal_value(self, data):
1626
1626
self .fail ('not_a_list' , input_type = type (data ).__name__ )
1627
1627
if not self .allow_empty and len (data ) == 0 :
1628
1628
self .fail ('empty' )
1629
- return [ self .child . run_validation ( item ) for item in data ]
1629
+ return self .run_child_validation ( data )
1630
1630
1631
1631
def to_representation (self , data ):
1632
1632
"""
1633
1633
List of object instances -> List of dicts of primitive datatypes.
1634
1634
"""
1635
1635
return [self .child .to_representation (item ) if item is not None else None for item in data ]
1636
1636
1637
+ def run_child_validation (self , data ):
1638
+ result = []
1639
+ errors = {}
1640
+
1641
+ for idx , item in enumerate (data ):
1642
+ try :
1643
+ result .append (self .child .run_validation (item ))
1644
+ except ValidationError as e :
1645
+ errors [idx ] = e .detail
1646
+
1647
+ if not errors :
1648
+ return result
1649
+ raise ValidationError (errors )
1650
+
1637
1651
1638
1652
class DictField (Field ):
1639
1653
child = _UnvalidatedField ()
@@ -1669,10 +1683,7 @@ def to_internal_value(self, data):
1669
1683
data = html .parse_html_dict (data )
1670
1684
if not isinstance (data , dict ):
1671
1685
self .fail ('not_a_dict' , input_type = type (data ).__name__ )
1672
- return {
1673
- six .text_type (key ): self .child .run_validation (value )
1674
- for key , value in data .items ()
1675
- }
1686
+ return self .run_child_validation (data )
1676
1687
1677
1688
def to_representation (self , value ):
1678
1689
"""
@@ -1683,6 +1694,22 @@ def to_representation(self, value):
1683
1694
for key , val in value .items ()
1684
1695
}
1685
1696
1697
+ def run_child_validation (self , data ):
1698
+ result = {}
1699
+ errors = {}
1700
+
1701
+ for key , value in data .items ():
1702
+ key = six .text_type (key )
1703
+
1704
+ try :
1705
+ result [key ] = self .child .run_validation (value )
1706
+ except ValidationError as e :
1707
+ errors [key ] = e .detail
1708
+
1709
+ if not errors :
1710
+ return result
1711
+ raise ValidationError (errors )
1712
+
1686
1713
1687
1714
class JSONField (Field ):
1688
1715
default_error_messages = {
0 commit comments