diff --git a/AUTHORS b/AUTHORS index ffd63227..484ab086 100644 --- a/AUTHORS +++ b/AUTHORS @@ -210,3 +210,4 @@ that much better: * Jay Shirley (https://github.com/jshirley) * DavidBord (https://github.com/DavidBord) * Axel Haustant (https://github.com/noirbizarre) + * Vyacheslav Murashkin (https://github.com/a4tunado) diff --git a/mongoengine/base/document.py b/mongoengine/base/document.py index 869449f9..c3802e1f 100644 --- a/mongoengine/base/document.py +++ b/mongoengine/base/document.py @@ -229,7 +229,7 @@ class BaseDocument(object): u = self.__str__() except (UnicodeEncodeError, UnicodeDecodeError): u = '[Bad Unicode data]' - repr_type = type(u) + repr_type = str if u is None else type(u) return repr_type('<%s: %s>' % (self.__class__.__name__, u)) def __str__(self): diff --git a/tests/document/instance.py b/tests/document/instance.py index f925aeeb..3233304e 100644 --- a/tests/document/instance.py +++ b/tests/document/instance.py @@ -103,6 +103,19 @@ class InstanceTest(unittest.TestCase): self.assertEqual('', repr(doc)) + def test_repr_none(self): + """Ensure None values handled correctly + """ + class Article(Document): + title = StringField() + + def __str__(self): + return None + + doc = Article(title=u'привет мир') + + self.assertEqual('', repr(doc)) + def test_queryset_resurrects_dropped_collection(self): self.Person.drop_collection()