From 17a1844b6ff7a26aa3522a38a21a6b586dca5b26 Mon Sep 17 00:00:00 2001 From: Thomas Steinacher Date: Mon, 17 Jun 2013 06:35:52 -0700 Subject: [PATCH] Don't raise exception if ListField/DictField are stored as None --- mongoengine/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mongoengine/fields.py b/mongoengine/fields.py index b270984..ec206d0 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -527,7 +527,7 @@ class ListField(ComplexBaseField): def to_python(self, val): to_python = getattr(self.field, 'to_python', None) - return [to_python(v) for v in val] if to_python else val + return [to_python(v) for v in val] if to_python and val else val or None def to_mongo(self, val): to_mongo = getattr(self.field, 'to_mongo', None) @@ -615,7 +615,7 @@ class DictField(ComplexBaseField): def to_python(self, val): to_python = getattr(self.field, 'to_python', None) - return {k: to_python(v) for k, v in val.iteritems()} if to_python else val + return {k: to_python(v) for k, v in val.iteritems()} if to_python and val else val or None def value_for_instance(self, value, instance, name=None): name = name or self.name