-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add kwargs into insert method #2169 #2170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,7 +288,8 @@ def first(self): | |
return result | ||
|
||
def insert( | ||
self, doc_or_docs, load_bulk=True, write_concern=None, signal_kwargs=None | ||
self, doc_or_docs, load_bulk=True, write_concern=None, signal_kwargs=None, | ||
**kwargs | ||
): | ||
"""bulk insert documents | ||
|
||
|
@@ -323,6 +324,10 @@ def insert( | |
return_one = True | ||
docs = [docs] | ||
|
||
if return_one and 'ordered' in kwargs: | ||
# insert_one does not accept `ordered` argument | ||
kwargs.pop('ordered') | ||
|
||
for doc in docs: | ||
if not isinstance(doc, self._document): | ||
msg = "Some documents inserted aren't instances of %s" % str( | ||
|
@@ -345,7 +350,7 @@ def insert( | |
insert_func = collection.insert_one | ||
|
||
try: | ||
inserted_result = insert_func(raw) | ||
inserted_result = insert_func(raw, **kwargs) | ||
ids = ( | ||
[inserted_result.inserted_id] | ||
if return_one | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see a potential bug related to the following code (that is a bit below in this method):
In case you provide ordered=False and it raises an error (e.g if you try to insert 2 times a document with same pk), that piece of code won't be reached, leaving the mongoengine documents without id's. Instead of relying on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw in case of successful unordered insert, I'm also unsure if we could rely on zip , as I don't know if we can rely on the order of |
||
|
Uh oh!
There was an error while loading. Please reload this page.