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 - 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
================= =================

View File

@ -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

View File

@ -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)):