Skip to content

Commit 546554a

Browse files
committed
made QuerySet.bulk_create() set pk on created model instances
1 parent c098777 commit 546554a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

django_mongodb/compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,13 +677,13 @@ def execute_sql(self, returning_fields=None):
677677

678678
field_values[field.column] = value
679679
objs.append(field_values)
680-
return [self.insert(objs, returning_fields=returning_fields)]
680+
return self.insert(objs, returning_fields=returning_fields)
681681

682682
@wrap_database_errors
683683
def insert(self, docs, returning_fields=None):
684684
"""Store a list of documents using field columns as element names."""
685685
inserted_ids = self.collection.insert_many(docs).inserted_ids
686-
return inserted_ids if returning_fields else []
686+
return [(x,) for x in inserted_ids] if returning_fields else []
687687

688688
@cached_property
689689
def collection_name(self):

django_mongodb/features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
1010
allows_multiple_constraints_on_same_fields = False
1111
can_create_inline_fk = False
1212
can_introspect_foreign_keys = False
13+
can_return_rows_from_bulk_insert = True
1314
greatest_least_ignores_nulls = True
1415
has_json_object_function = False
1516
has_native_json_field = True

0 commit comments

Comments
 (0)