Add SaveConditionError exception
This commit is contained in:
		| @@ -16,7 +16,8 @@ from mongoengine.base import ( | |||||||
|     ALLOW_INHERITANCE, |     ALLOW_INHERITANCE, | ||||||
|     get_document |     get_document | ||||||
| ) | ) | ||||||
| from mongoengine.errors import InvalidQueryError, InvalidDocumentError | from mongoengine.errors import (InvalidQueryError, InvalidDocumentError, | ||||||
|  |                                 SaveConditionError) | ||||||
| from mongoengine.python_support import IS_PYMONGO_3 | from mongoengine.python_support import IS_PYMONGO_3 | ||||||
| from mongoengine.queryset import (OperationError, NotUniqueError, | from mongoengine.queryset import (OperationError, NotUniqueError, | ||||||
|                                   QuerySet, transform) |                                   QuerySet, transform) | ||||||
| @@ -359,7 +360,7 @@ class Document(BaseDocument): | |||||||
|                     last_error = collection.update(select_dict, update_query, |                     last_error = collection.update(select_dict, update_query, | ||||||
|                                                    upsert=upsert, **write_concern) |                                                    upsert=upsert, **write_concern) | ||||||
|                     if not upsert and last_error['nModified'] == 0: |                     if not upsert and last_error['nModified'] == 0: | ||||||
|                         raise OperationError('Race condition preventing' |                         raise SaveConditionError('Race condition preventing' | ||||||
|                                                  ' document update detected') |                                                  ' document update detected') | ||||||
|                     created = is_new_object(last_error) |                     created = is_new_object(last_error) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -41,6 +41,10 @@ class NotUniqueError(OperationError): | |||||||
|     pass |     pass | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class SaveConditionError(OperationError): | ||||||
|  |     pass | ||||||
|  |  | ||||||
|  |  | ||||||
| class FieldDoesNotExist(Exception): | class FieldDoesNotExist(Exception): | ||||||
|     """Raised when trying to set a field |     """Raised when trying to set a field | ||||||
|     not declared in a :class:`~mongoengine.Document` |     not declared in a :class:`~mongoengine.Document` | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user