drop an unnecessary ALLOW_INHERITANCE

This commit is contained in:
Stefan Wojcik 2016-12-08 11:22:51 -05:00
parent ae777e45b2
commit 18a91cc794
6 changed files with 16 additions and 29 deletions

View File

@ -12,8 +12,7 @@ from mongoengine.base.metaclasses import *
__all__ = (
# common
'ALLOW_INHERITANCE', 'UPDATE_OPERATORS', '_document_registry',
'get_document',
'UPDATE_OPERATORS', '_document_registry', 'get_document',
# datastructures
'BaseDict', 'BaseList', 'EmbeddedDocumentList',

View File

@ -1,10 +1,6 @@
from mongoengine.errors import NotRegistered
__all__ = ('ALLOW_INHERITANCE', 'UPDATE_OPERATORS', 'get_document',
'_document_registry')
ALLOW_INHERITANCE = False # TODO is this really necessary?
__all__ = ('UPDATE_OPERATORS', 'get_document', '_document_registry')
UPDATE_OPERATORS = set(['set', 'unset', 'inc', 'dec', 'pop', 'push',

View File

@ -11,7 +11,7 @@ import pymongo
import six
from mongoengine import signals
from mongoengine.base.common import ALLOW_INHERITANCE, get_document
from mongoengine.base.common import get_document
from mongoengine.base.datastructures import (BaseDict, BaseList,
EmbeddedDocumentList,
SemiStrictDict, StrictDict)
@ -353,7 +353,7 @@ class BaseDocument(object):
data[field.name] = value
# Only add _cls if allow_inheritance is True
if not self._meta.get('allow_inheritance', ALLOW_INHERITANCE):
if not self._meta.get('allow_inheritance'):
data.pop('_cls')
return data
@ -765,8 +765,7 @@ class BaseDocument(object):
direction = None
# Check to see if we need to include _cls
allow_inheritance = cls._meta.get('allow_inheritance',
ALLOW_INHERITANCE)
allow_inheritance = cls._meta.get('allow_inheritance')
include_cls = (
allow_inheritance and
not spec.get('sparse', False) and

View File

@ -6,7 +6,7 @@ from bson import DBRef, ObjectId, SON
import pymongo
import six
from mongoengine.base.common import ALLOW_INHERITANCE, UPDATE_OPERATORS
from mongoengine.base.common import UPDATE_OPERATORS
from mongoengine.base.datastructures import (BaseDict, BaseList,
EmbeddedDocumentList)
from mongoengine.common import _import_class
@ -376,9 +376,7 @@ class ComplexBaseField(BaseField):
# any _cls data so make it a generic reference allows
# us to dereference
meta = getattr(v, '_meta', {})
allow_inheritance = (
meta.get('allow_inheritance', ALLOW_INHERITANCE)
is True)
allow_inheritance = meta.get('allow_inheritance')
if not allow_inheritance and not self.field:
value_dict[k] = GenericReferenceField().to_mongo(v)
else:

View File

@ -1,6 +1,6 @@
import warnings
from mongoengine.base.common import ALLOW_INHERITANCE, _document_registry
from mongoengine.base.common import _document_registry
from mongoengine.base.fields import BaseField, ComplexBaseField, ObjectIdField
from mongoengine.common import _import_class
from mongoengine.errors import InvalidDocumentError
@ -45,7 +45,7 @@ class DocumentMetaclass(type):
attrs['_meta'] = meta
attrs['_meta']['abstract'] = False # 789: EmbeddedDocument shouldn't inherit abstract
if attrs['_meta'].get('allow_inheritance', ALLOW_INHERITANCE):
if attrs['_meta'].get('allow_inheritance'):
StringField = _import_class('StringField')
attrs['_cls'] = StringField()
@ -116,10 +116,8 @@ class DocumentMetaclass(type):
if hasattr(base, '_meta'):
# Warn if allow_inheritance isn't set and prevent
# inheritance of classes where inheritance is set to False
allow_inheritance = base._meta.get('allow_inheritance',
ALLOW_INHERITANCE)
if (allow_inheritance is not True and
not base._meta.get('abstract')):
allow_inheritance = base._meta.get('allow_inheritance')
if not allow_inheritance and not base._meta.get('abstract'):
raise ValueError('Document %s may not be subclassed' %
base.__name__)

View File

@ -7,10 +7,9 @@ from pymongo.read_preferences import ReadPreference
import six
from mongoengine import signals
from mongoengine.base import (ALLOW_INHERITANCE, BaseDict, BaseDocument,
BaseList, DocumentMetaclass,
EmbeddedDocumentList, TopLevelDocumentMetaclass,
get_document)
from mongoengine.base import (BaseDict, BaseDocument, BaseList,
DocumentMetaclass, EmbeddedDocumentList,
TopLevelDocumentMetaclass, get_document)
from mongoengine.common import _import_class
from mongoengine.connection import DEFAULT_CONNECTION_NAME, get_db
from mongoengine.context_managers import switch_collection, switch_db
@ -813,8 +812,7 @@ class Document(BaseDocument):
# If _cls is being used (for polymorphism), it needs an index,
# only if another index doesn't begin with _cls
if (index_cls and not cls_indexed and
cls._meta.get('allow_inheritance', ALLOW_INHERITANCE) is True):
if index_cls and not cls_indexed and cls._meta.get('allow_inheritance'):
# we shouldn't pass 'cls' to the collection.ensureIndex options
# because of https://jira.mongodb.org/browse/SERVER-769
@ -884,8 +882,7 @@ class Document(BaseDocument):
# finish up by appending { '_id': 1 } and { '_cls': 1 }, if needed
if [(u'_id', 1)] not in indexes:
indexes.append([(u'_id', 1)])
if (cls._meta.get('index_cls', True) and
cls._meta.get('allow_inheritance', ALLOW_INHERITANCE) is True):
if (cls._meta.get('index_cls', True) and cls._meta.get('allow_inheritance')):
indexes.append([(u'_cls', 1)])
return indexes