flask-peewee
flask-peewee copied to clipboard
Serializer clean_data doesn't work with array values
https://github.com/coleifer/flask-peewee/blob/0.6.5/flask_peewee/serializer.py#L25
elif isinstance(value, (list, tuple)):
data[key] = map(self.clean_data, value)
This fails in a few ways. clean_data will be called, but actually will receive the first item in the array, since map accepts *args
. Even if the array was passed through, it will not work b/c array doesn't have a .items()
method. I think a safer implementation would be something like
def clean_data(self, data):
if isinstance(data, dict):
for key, value in data.items():
data[key] = self.clean_data(value)
elif isinstance(data, (list, tuple)):
for i, item in enumerate(data):
data[i] = self.clean_data(item)
else:
data = self.convert_value(data)
return data
I think the assumption is that the list contains dicts. I'm not sure about map
taking *args
.
My use was I was trying to serialize an arbitrary JSONField out, and it failed. I could have dicts of lists of lists of dicts, etc.