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
4 changes: 3 additions & 1 deletion mongoengine/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ def save(self, force_insert=False, validate=True, clean=True,
.. versionchanged:: 0.10.7
Add signal_kwargs argument
"""
if self._meta.get('abstract'):
raise InvalidDocumentError('Cannot save an abstract document.')

signal_kwargs = signal_kwargs or {}
signals.pre_save.send(self.__class__, document=self, **signal_kwargs)

Expand Down Expand Up @@ -828,7 +831,6 @@ def list_indexes(cls):
""" Lists all of the indexes that should be created for given
collection. It includes all the indexes from super- and sub-classes.
"""

if cls._meta.get('abstract'):
return []

Expand Down
9 changes: 9 additions & 0 deletions tests/document/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ def test_to_dbref(self):

person.to_dbref()

def test_save_abstract_document(self):
"""Saving an abstract document should fail."""
class Doc(Document):
name = StringField()
meta = {'abstract': True}

with self.assertRaises(InvalidDocumentError):
Doc(name='aaa').save()

def test_reload(self):
"""Ensure that attributes may be reloaded.
"""
Expand Down