diff --git a/AUTHORS b/AUTHORS index 34f8903f..23930cc3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -211,3 +211,4 @@ that much better: * DavidBord (https://github.com/DavidBord) * Axel Haustant (https://github.com/noirbizarre) * David Czarnecki (https://github.com/czarneckid) + * Vyacheslav Murashkin (https://github.com/a4tunado) diff --git a/mongoengine/base/document.py b/mongoengine/base/document.py index 05fd1faf..bf5bdf79 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 360d5385..a22f3fbf 100644 --- a/tests/document/instance.py +++ b/tests/document/instance.py @@ -112,6 +112,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()