mirror of
https://github.com/django/django.git
synced 2025-11-25 21:22:14 +00:00
Fixed #36502 -- Restored UNNEST strategy for foreign key bulk inserts on PostgreSQL.
Some checks failed
Docs / docs (push) Has been cancelled
Tests / Windows, SQLite, Python 3.13 (push) Has been cancelled
Tests / JavaScript tests (push) Has been cancelled
Linters / black (push) Has been cancelled
Docs / blacken-docs (push) Has been cancelled
Linters / flake8 (push) Has been cancelled
Linters / isort (push) Has been cancelled
Some checks failed
Docs / docs (push) Has been cancelled
Tests / Windows, SQLite, Python 3.13 (push) Has been cancelled
Tests / JavaScript tests (push) Has been cancelled
Linters / black (push) Has been cancelled
Docs / blacken-docs (push) Has been cancelled
Linters / flake8 (push) Has been cancelled
Linters / isort (push) Has been cancelled
Regression in 764af7a3d6.
This commit is contained in:
parent
994950e886
commit
0fe218842e
3 changed files with 21 additions and 3 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import unittest
|
||||
from datetime import date
|
||||
|
||||
from django.db import connection
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.test import TestCase
|
||||
|
||||
from ..models import Square
|
||||
from ..models import Article, Reporter, Square
|
||||
|
||||
|
||||
@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL tests")
|
||||
|
|
@ -33,3 +34,17 @@ class BulkCreateUnnestTests(TestCase):
|
|||
squares = Square.objects.bulk_create([Square(root=3), Square(root=3)])
|
||||
self.assertIn("UNNEST", ctx[0]["sql"])
|
||||
self.assertEqual([square.square for square in squares], [9, 9])
|
||||
|
||||
def test_unnest_eligible_foreign_keys(self):
|
||||
reporter = Reporter.objects.create()
|
||||
with self.assertNumQueries(1) as ctx:
|
||||
articles = Article.objects.bulk_create(
|
||||
[
|
||||
Article(pub_date=date.today(), reporter=reporter),
|
||||
Article(pub_date=date.today(), reporter=reporter),
|
||||
]
|
||||
)
|
||||
self.assertIn("UNNEST", ctx[0]["sql"])
|
||||
self.assertEqual(
|
||||
[article.reporter for article in articles], [reporter, reporter]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue