Merge pull request #1196 from nickptrvc/master

Fix pre_bulk_insert signal
This commit is contained in:
Omer Katz
2016-01-30 12:25:29 +02:00
2 changed files with 52 additions and 3 deletions

View File

@@ -296,7 +296,6 @@ class BaseQuerySet(object):
return_one = True
docs = [docs]
raw = []
for doc in docs:
if not isinstance(doc, self._document):
msg = ("Some documents inserted aren't instances of %s"
@@ -305,9 +304,10 @@ class BaseQuerySet(object):
if doc.pk and not doc._created:
msg = "Some documents have ObjectIds use doc.update() instead"
raise OperationError(msg)
raw.append(doc.to_mongo())
signals.pre_bulk_insert.send(self._document, documents=docs)
raw = [doc.to_mongo() for doc in docs]
try:
ids = self._collection.insert(raw, **write_concern)
except pymongo.errors.DuplicateKeyError, err: