@@ -1211,13 +1211,19 @@ def model_to_dict(model_instance, serialize=True):
1211
1211
# exist in attribute_map
1212
1212
attr = model_instance.attribute_map.get(attr, attr)
1213
1213
if isinstance(value, list):
1214
- if not value or isinstance(value[0], PRIMITIVE_TYPES):
1215
- # empty list or primitive types
1216
- result[attr] = value
1217
- elif isinstance(value[0], ModelSimple):
1218
- result[attr] = [x.value for x in value]
1219
- else:
1220
- result[attr] = [model_to_dict(x, serialize=serialize) for x in value]
1214
+ if not value:
1215
+ # empty list or None
1216
+ result[attr] = value
1217
+ else:
1218
+ res = []
1219
+ for v in value:
1220
+ if isinstance(v, PRIMITIVE_TYPES) or v is None:
1221
+ res.append(v)
1222
+ elif isinstance(v, ModelSimple):
1223
+ res.append(v.value)
1224
+ else:
1225
+ res.append(model_to_dict(v, serialize=serialize))
1226
+ result[attr] = res
1221
1227
elif isinstance(value, dict):
1222
1228
result[attr] = dict(map(
1223
1229
lambda item: (item[0],
@@ -1277,11 +1283,16 @@ def get_valid_classes_phrase(input_classes):
1277
1283
def convert_js_args_to_python_args(fn):
1278
1284
from functools import wraps
1279
1285
@wraps(fn)
1280
- def wrapped_init(self, *args, **kwargs):
1286
+ def wrapped_init(_self, *args, **kwargs):
1287
+ """
1288
+ An attribute named `self` received from the api will conflicts with the reserved `self`
1289
+ parameter of a class method. During generation, `self` attributes are mapped
1290
+ to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
1291
+ """
1281
1292
spec_property_naming = kwargs.get('_spec_property_naming', False)
1282
1293
if spec_property_naming:
1283
- kwargs = change_keys_js_to_python(kwargs, self .__class__)
1284
- return fn(self , *args, **kwargs)
1294
+ kwargs = change_keys_js_to_python(kwargs, _self .__class__)
1295
+ return fn(_self , *args, **kwargs)
1285
1296
return wrapped_init
1286
1297
1287
1298
0 commit comments