Fix pre_bulk_insert signal

This commit is contained in:
Nick Pjetrovic
2015-12-24 18:30:46 -05:00
parent 0372e07eb0
commit acc7448dc5
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: