Skip to content

Commit

Permalink
Moved injection of Exceptions to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Sep 26, 2012
1 parent 6a4351e commit e2c7804
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions mongoengine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,17 +635,6 @@ def __new__(cls, name, bases, attrs):
"field name" % field.name)
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
_document_registry[new_class._class_name] = new_class

Expand Down Expand Up @@ -836,6 +825,17 @@ def __new__(cls, name, bases, attrs):
new_class._fields['id'] = ObjectIdField(db_field='_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

@classmethod
Expand Down

0 comments on commit e2c7804

Please sign in to comment.