Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mongoengine/base/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ def __init__(self, db_field=None, name=None, required=False, default=None,
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
Expand Down
2 changes: 1 addition & 1 deletion tests/document/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Zoo(Document):
Zoo.drop_collection()

class Zoo(Document):
animals = ListField(GenericReferenceField(Animal))
animals = ListField(GenericReferenceField())

# Save a reference to each animal
zoo = Zoo(animals=Animal.objects)
Expand Down