1313from .serialization import SerializePipeline
1414
1515
16- @pipe ()
16+ @pipe (run_if_none = True )
1717def marshall_collection (session ):
1818 """iterate over each item in ``data`` and marshal the item through the
1919 wrapped field defined for this collection
@@ -26,24 +26,25 @@ def marshall_collection(session):
2626
2727 output = []
2828
29- if not hasattr (session .data , '__iter__' ):
30- raise session .field .invalid ('type_error' )
31-
32- for i , datum in enumerate (session .data ):
33- _output = {}
34- # If the object already exists, try to match up the existing elements
35- # with those in the input json
36- if existing_value is not None :
37- try :
38- _output [wrapped_field .opts .source ] = existing_value [i ]
39- except IndexError :
40- pass
41-
42- mapper_session = session .mapper .get_mapper_session (datum , _output )
43- wrapped_field .marshal (mapper_session , parent_session = session )
44-
45- result = _output [wrapped_field .opts .source ]
46- output .append (result )
29+ if session .data is not None :
30+ if not hasattr (session .data , '__iter__' ):
31+ raise session .field .invalid ('type_error' )
32+
33+ for i , datum in enumerate (session .data ):
34+ _output = {}
35+ # If the object already exists, try to match up the existing elements
36+ # with those in the input json
37+ if existing_value is not None :
38+ try :
39+ _output [wrapped_field .opts .source ] = existing_value [i ]
40+ except IndexError :
41+ pass
42+
43+ mapper_session = session .mapper .get_mapper_session (datum , _output )
44+ wrapped_field .marshal (mapper_session , parent_session = session )
45+
46+ result = _output [wrapped_field .opts .source ]
47+ output .append (result )
4748
4849 session .data = output
4950 return session .data
0 commit comments