From ae777e45b23f5d3491a8ac1167f5dd0ff677f3b0 Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Thu, 8 Dec 2016 11:15:35 -0500 Subject: [PATCH] better comment about overriding allow_inheritance --- mongoengine/base/metaclasses.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mongoengine/base/metaclasses.py b/mongoengine/base/metaclasses.py index 97283451..bb438f85 100644 --- a/mongoengine/base/metaclasses.py +++ b/mongoengine/base/metaclasses.py @@ -334,12 +334,16 @@ class TopLevelDocumentMetaclass(DocumentMetaclass): meta.merge(attrs.get('_meta', {})) # Top level meta - # Only simple classes (direct subclasses of Document) - # may set allow_inheritance to False + # Only simple classes (i.e. direct subclasses of Document) may set + # allow_inheritance to False. If the base Document allows inheritance, + # none of its subclasses can override allow_inheritance to False. simple_class = all([b._meta.get('abstract') for b in flattened_bases if hasattr(b, '_meta')]) - if (not simple_class and meta['allow_inheritance'] is False and - not meta['abstract']): + if ( + not simple_class and + meta['allow_inheritance'] is False and + not meta['abstract'] + ): raise ValueError('Only direct subclasses of Document may set ' '"allow_inheritance" to False')