Moved injection of Exceptions to top level
This commit is contained in:
parent
6a4351e44f
commit
e2c78047b1
@ -635,17 +635,6 @@ class DocumentMetaclass(type):
|
|||||||
"field name" % field.name)
|
"field name" % field.name)
|
||||||
raise InvalidDocumentError(msg)
|
raise InvalidDocumentError(msg)
|
||||||
|
|
||||||
# Merge in exceptions with parent hierarchy
|
|
||||||
exceptions_to_merge = (DoesNotExist, MultipleObjectsReturned)
|
|
||||||
module = attrs.get('__module__')
|
|
||||||
for exc in exceptions_to_merge:
|
|
||||||
name = exc.__name__
|
|
||||||
parents = tuple(getattr(base, name) for base in flattened_bases
|
|
||||||
if hasattr(base, name)) or (exc,)
|
|
||||||
# Create new exception and set to new_class
|
|
||||||
exception = type(name, parents, {'__module__': module})
|
|
||||||
setattr(new_class, name, exception)
|
|
||||||
|
|
||||||
# Add class to the _document_registry
|
# Add class to the _document_registry
|
||||||
_document_registry[new_class._class_name] = new_class
|
_document_registry[new_class._class_name] = new_class
|
||||||
|
|
||||||
@ -836,6 +825,17 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
|
|||||||
new_class._fields['id'] = ObjectIdField(db_field='_id')
|
new_class._fields['id'] = ObjectIdField(db_field='_id')
|
||||||
new_class.id = new_class._fields['id']
|
new_class.id = new_class._fields['id']
|
||||||
|
|
||||||
|
# Merge in exceptions with parent hierarchy
|
||||||
|
exceptions_to_merge = (DoesNotExist, MultipleObjectsReturned)
|
||||||
|
module = attrs.get('__module__')
|
||||||
|
for exc in exceptions_to_merge:
|
||||||
|
name = exc.__name__
|
||||||
|
parents = tuple(getattr(base, name) for base in flattened_bases
|
||||||
|
if hasattr(base, name)) or (exc,)
|
||||||
|
# Create new exception and set to new_class
|
||||||
|
exception = type(name, parents, {'__module__': module})
|
||||||
|
setattr(new_class, name, exception)
|
||||||
|
|
||||||
return new_class
|
return new_class
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user