Merge pull request #2153 from erdenezul/misleading_bulkwrite_error

Change misleading error message
This commit is contained in:
erdenezul 2019-09-04 09:42:10 +02:00 committed by GitHub
commit 564a2b5f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -18,6 +18,7 @@ Development
- 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
- 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
=================

View File

@ -12,6 +12,7 @@ __all__ = (
"InvalidQueryError",
"OperationError",
"NotUniqueError",
"BulkWriteError",
"FieldDoesNotExist",
"ValidationError",
"SaveConditionError",
@ -51,6 +52,10 @@ class NotUniqueError(OperationError):
pass
class BulkWriteError(OperationError):
pass
class SaveConditionError(OperationError):
pass

View File

@ -20,6 +20,7 @@ from mongoengine.common import _import_class
from mongoengine.connection import get_db
from mongoengine.context_managers import set_write_concern, switch_db
from mongoengine.errors import (
BulkWriteError,
InvalidQueryError,
LookUpError,
NotUniqueError,
@ -355,8 +356,8 @@ class BaseQuerySet(object):
except pymongo.errors.BulkWriteError as err:
# inserting documents that already have an _id field will
# give huge performance debt or raise
message = u"Document must not have _id value before bulk write (%s)"
raise NotUniqueError(message % six.text_type(err))
message = u"Bulk write error: (%s)"
raise BulkWriteError(message % six.text_type(err.details))
except pymongo.errors.OperationFailure as err:
message = "Could not save document (%s)"
if re.match("^E1100[01] duplicate key", six.text_type(err)):