drop an unnecessary ALLOW_INHERITANCE
This commit is contained in:
parent
ae777e45b2
commit
18a91cc794
@ -12,8 +12,7 @@ from mongoengine.base.metaclasses import *
|
|||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
# common
|
# common
|
||||||
'ALLOW_INHERITANCE', 'UPDATE_OPERATORS', '_document_registry',
|
'UPDATE_OPERATORS', '_document_registry', 'get_document',
|
||||||
'get_document',
|
|
||||||
|
|
||||||
# datastructures
|
# datastructures
|
||||||
'BaseDict', 'BaseList', 'EmbeddedDocumentList',
|
'BaseDict', 'BaseList', 'EmbeddedDocumentList',
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
from mongoengine.errors import NotRegistered
|
from mongoengine.errors import NotRegistered
|
||||||
|
|
||||||
__all__ = ('ALLOW_INHERITANCE', 'UPDATE_OPERATORS', 'get_document',
|
__all__ = ('UPDATE_OPERATORS', 'get_document', '_document_registry')
|
||||||
'_document_registry')
|
|
||||||
|
|
||||||
|
|
||||||
ALLOW_INHERITANCE = False # TODO is this really necessary?
|
|
||||||
|
|
||||||
|
|
||||||
UPDATE_OPERATORS = set(['set', 'unset', 'inc', 'dec', 'pop', 'push',
|
UPDATE_OPERATORS = set(['set', 'unset', 'inc', 'dec', 'pop', 'push',
|
||||||
|
@ -11,7 +11,7 @@ import pymongo
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from mongoengine import signals
|
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,
|
from mongoengine.base.datastructures import (BaseDict, BaseList,
|
||||||
EmbeddedDocumentList,
|
EmbeddedDocumentList,
|
||||||
SemiStrictDict, StrictDict)
|
SemiStrictDict, StrictDict)
|
||||||
@ -353,7 +353,7 @@ class BaseDocument(object):
|
|||||||
data[field.name] = value
|
data[field.name] = value
|
||||||
|
|
||||||
# Only add _cls if allow_inheritance is True
|
# 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')
|
data.pop('_cls')
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -765,8 +765,7 @@ class BaseDocument(object):
|
|||||||
direction = None
|
direction = None
|
||||||
|
|
||||||
# Check to see if we need to include _cls
|
# Check to see if we need to include _cls
|
||||||
allow_inheritance = cls._meta.get('allow_inheritance',
|
allow_inheritance = cls._meta.get('allow_inheritance')
|
||||||
ALLOW_INHERITANCE)
|
|
||||||
include_cls = (
|
include_cls = (
|
||||||
allow_inheritance and
|
allow_inheritance and
|
||||||
not spec.get('sparse', False) and
|
not spec.get('sparse', False) and
|
||||||
|
@ -6,7 +6,7 @@ from bson import DBRef, ObjectId, SON
|
|||||||
import pymongo
|
import pymongo
|
||||||
import six
|
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,
|
from mongoengine.base.datastructures import (BaseDict, BaseList,
|
||||||
EmbeddedDocumentList)
|
EmbeddedDocumentList)
|
||||||
from mongoengine.common import _import_class
|
from mongoengine.common import _import_class
|
||||||
@ -376,9 +376,7 @@ class ComplexBaseField(BaseField):
|
|||||||
# any _cls data so make it a generic reference allows
|
# any _cls data so make it a generic reference allows
|
||||||
# us to dereference
|
# us to dereference
|
||||||
meta = getattr(v, '_meta', {})
|
meta = getattr(v, '_meta', {})
|
||||||
allow_inheritance = (
|
allow_inheritance = meta.get('allow_inheritance')
|
||||||
meta.get('allow_inheritance', ALLOW_INHERITANCE)
|
|
||||||
is True)
|
|
||||||
if not allow_inheritance and not self.field:
|
if not allow_inheritance and not self.field:
|
||||||
value_dict[k] = GenericReferenceField().to_mongo(v)
|
value_dict[k] = GenericReferenceField().to_mongo(v)
|
||||||
else:
|
else:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import warnings
|
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.base.fields import BaseField, ComplexBaseField, ObjectIdField
|
||||||
from mongoengine.common import _import_class
|
from mongoengine.common import _import_class
|
||||||
from mongoengine.errors import InvalidDocumentError
|
from mongoengine.errors import InvalidDocumentError
|
||||||
@ -45,7 +45,7 @@ class DocumentMetaclass(type):
|
|||||||
attrs['_meta'] = meta
|
attrs['_meta'] = meta
|
||||||
attrs['_meta']['abstract'] = False # 789: EmbeddedDocument shouldn't inherit abstract
|
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')
|
StringField = _import_class('StringField')
|
||||||
attrs['_cls'] = StringField()
|
attrs['_cls'] = StringField()
|
||||||
|
|
||||||
@ -116,10 +116,8 @@ class DocumentMetaclass(type):
|
|||||||
if hasattr(base, '_meta'):
|
if hasattr(base, '_meta'):
|
||||||
# Warn if allow_inheritance isn't set and prevent
|
# Warn if allow_inheritance isn't set and prevent
|
||||||
# inheritance of classes where inheritance is set to False
|
# inheritance of classes where inheritance is set to False
|
||||||
allow_inheritance = base._meta.get('allow_inheritance',
|
allow_inheritance = base._meta.get('allow_inheritance')
|
||||||
ALLOW_INHERITANCE)
|
if not allow_inheritance and not base._meta.get('abstract'):
|
||||||
if (allow_inheritance is not True and
|
|
||||||
not base._meta.get('abstract')):
|
|
||||||
raise ValueError('Document %s may not be subclassed' %
|
raise ValueError('Document %s may not be subclassed' %
|
||||||
base.__name__)
|
base.__name__)
|
||||||
|
|
||||||
|
@ -7,10 +7,9 @@ from pymongo.read_preferences import ReadPreference
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from mongoengine import signals
|
from mongoengine import signals
|
||||||
from mongoengine.base import (ALLOW_INHERITANCE, BaseDict, BaseDocument,
|
from mongoengine.base import (BaseDict, BaseDocument, BaseList,
|
||||||
BaseList, DocumentMetaclass,
|
DocumentMetaclass, EmbeddedDocumentList,
|
||||||
EmbeddedDocumentList, TopLevelDocumentMetaclass,
|
TopLevelDocumentMetaclass, get_document)
|
||||||
get_document)
|
|
||||||
from mongoengine.common import _import_class
|
from mongoengine.common import _import_class
|
||||||
from mongoengine.connection import DEFAULT_CONNECTION_NAME, get_db
|
from mongoengine.connection import DEFAULT_CONNECTION_NAME, get_db
|
||||||
from mongoengine.context_managers import switch_collection, switch_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,
|
# If _cls is being used (for polymorphism), it needs an index,
|
||||||
# only if another index doesn't begin with _cls
|
# only if another index doesn't begin with _cls
|
||||||
if (index_cls and not cls_indexed and
|
if index_cls and not cls_indexed and cls._meta.get('allow_inheritance'):
|
||||||
cls._meta.get('allow_inheritance', ALLOW_INHERITANCE) is True):
|
|
||||||
|
|
||||||
# we shouldn't pass 'cls' to the collection.ensureIndex options
|
# we shouldn't pass 'cls' to the collection.ensureIndex options
|
||||||
# because of https://jira.mongodb.org/browse/SERVER-769
|
# 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
|
# finish up by appending { '_id': 1 } and { '_cls': 1 }, if needed
|
||||||
if [(u'_id', 1)] not in indexes:
|
if [(u'_id', 1)] not in indexes:
|
||||||
indexes.append([(u'_id', 1)])
|
indexes.append([(u'_id', 1)])
|
||||||
if (cls._meta.get('index_cls', True) and
|
if (cls._meta.get('index_cls', True) and cls._meta.get('allow_inheritance')):
|
||||||
cls._meta.get('allow_inheritance', ALLOW_INHERITANCE) is True):
|
|
||||||
indexes.append([(u'_cls', 1)])
|
indexes.append([(u'_cls', 1)])
|
||||||
|
|
||||||
return indexes
|
return indexes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user