handle None from model __str__; Fixes #753
This commit is contained in:
parent
759f72169a
commit
7430b31697
1
AUTHORS
1
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)
|
||||
|
@ -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):
|
||||
|
@ -103,6 +103,19 @@ class InstanceTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual('<Article: привет мир>', 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('<Article: None>', repr(doc))
|
||||
|
||||
def test_queryset_resurrects_dropped_collection(self):
|
||||
self.Person.drop_collection()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user