mirror of
https://github.com/django/django.git
synced 2026-02-09 02:49:25 +08:00
Fixed #36702 -- Made bulk_create() return pk values set by an expression.
This commit is contained in:
@@ -842,7 +842,6 @@ class QuerySet(AltersData):
|
||||
)
|
||||
for obj_with_pk, results in zip(objs_with_pk, returned_columns):
|
||||
for result, field in zip(results, opts.db_returning_fields):
|
||||
if field != opts.pk:
|
||||
setattr(obj_with_pk, field.attname, result)
|
||||
for obj_with_pk in objs_with_pk:
|
||||
obj_with_pk._state.adding = False
|
||||
|
||||
@@ -884,6 +884,15 @@ class BulkCreateTests(TestCase):
|
||||
(obj,) = DbDefaultPrimaryKey.objects.bulk_create([DbDefaultPrimaryKey()])
|
||||
self.assertIsInstance(obj.id, datetime)
|
||||
|
||||
@skipUnlessDBFeature(
|
||||
"can_return_rows_from_bulk_insert", "supports_expression_defaults"
|
||||
)
|
||||
def test_db_expression_primary_key(self):
|
||||
(obj,) = DbDefaultPrimaryKey.objects.bulk_create(
|
||||
[DbDefaultPrimaryKey(id=Now())]
|
||||
)
|
||||
self.assertIsInstance(obj.id, datetime)
|
||||
|
||||
|
||||
@skipUnlessDBFeature("supports_transactions", "has_bulk_insert")
|
||||
class BulkCreateTransactionTests(TransactionTestCase):
|
||||
|
||||
Reference in New Issue
Block a user