Compare commits

...

1 Commits

Author SHA1 Message Date
Stefan Wojcik
7195236a3b better db_field validation 2017-05-07 20:26:52 -04:00
2 changed files with 9 additions and 2 deletions

View File

@ -81,7 +81,14 @@ class BaseField(object):
self.sparse = sparse
self._owner_document = None
# Validate the db_field
# Make sure db_field is a string (if it's explicitly defined).
if (
self.db_field is not None and
not isinstance(self.db_field, six.string_types)
):
raise TypeError('db_field should be a string.')
# Make sure db_field doesn't contain any forbidden characters.
if isinstance(self.db_field, six.string_types) and (
'.' in self.db_field or
'\0' in self.db_field or

View File

@ -242,7 +242,7 @@ class InstanceTest(unittest.TestCase):
Zoo.drop_collection()
class Zoo(Document):
animals = ListField(GenericReferenceField(Animal))
animals = ListField(GenericReferenceField())
# Save a reference to each animal
zoo = Zoo(animals=Animal.objects)