Merge pull request #2153 from erdenezul/misleading_bulkwrite_error
Change misleading error message
This commit is contained in:
commit
564a2b5f1e
@ -18,6 +18,7 @@ Development
|
|||||||
- Fix updating/modifying/deleting/reloading a document that's sharded by a field with ``db_field`` specified. #2125
|
- Fix updating/modifying/deleting/reloading a document that's sharded by a field with ``db_field`` specified. #2125
|
||||||
- ``ListField`` now accepts an optional ``max_length`` parameter. #2110
|
- ``ListField`` now accepts an optional ``max_length`` parameter. #2110
|
||||||
- The codebase is now formatted using ``black``. #2109
|
- The codebase is now formatted using ``black``. #2109
|
||||||
|
- In bulk write insert, the detailed error message would raise in exception.
|
||||||
|
|
||||||
Changes in 0.18.2
|
Changes in 0.18.2
|
||||||
=================
|
=================
|
||||||
|
@ -12,6 +12,7 @@ __all__ = (
|
|||||||
"InvalidQueryError",
|
"InvalidQueryError",
|
||||||
"OperationError",
|
"OperationError",
|
||||||
"NotUniqueError",
|
"NotUniqueError",
|
||||||
|
"BulkWriteError",
|
||||||
"FieldDoesNotExist",
|
"FieldDoesNotExist",
|
||||||
"ValidationError",
|
"ValidationError",
|
||||||
"SaveConditionError",
|
"SaveConditionError",
|
||||||
@ -51,6 +52,10 @@ class NotUniqueError(OperationError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class BulkWriteError(OperationError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SaveConditionError(OperationError):
|
class SaveConditionError(OperationError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from mongoengine.common import _import_class
|
|||||||
from mongoengine.connection import get_db
|
from mongoengine.connection import get_db
|
||||||
from mongoengine.context_managers import set_write_concern, switch_db
|
from mongoengine.context_managers import set_write_concern, switch_db
|
||||||
from mongoengine.errors import (
|
from mongoengine.errors import (
|
||||||
|
BulkWriteError,
|
||||||
InvalidQueryError,
|
InvalidQueryError,
|
||||||
LookUpError,
|
LookUpError,
|
||||||
NotUniqueError,
|
NotUniqueError,
|
||||||
@ -355,8 +356,8 @@ class BaseQuerySet(object):
|
|||||||
except pymongo.errors.BulkWriteError as err:
|
except pymongo.errors.BulkWriteError as err:
|
||||||
# inserting documents that already have an _id field will
|
# inserting documents that already have an _id field will
|
||||||
# give huge performance debt or raise
|
# give huge performance debt or raise
|
||||||
message = u"Document must not have _id value before bulk write (%s)"
|
message = u"Bulk write error: (%s)"
|
||||||
raise NotUniqueError(message % six.text_type(err))
|
raise BulkWriteError(message % six.text_type(err.details))
|
||||||
except pymongo.errors.OperationFailure as err:
|
except pymongo.errors.OperationFailure as err:
|
||||||
message = "Could not save document (%s)"
|
message = "Could not save document (%s)"
|
||||||
if re.match("^E1100[01] duplicate key", six.text_type(err)):
|
if re.match("^E1100[01] duplicate key", six.text_type(err)):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user