diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-07-10 12:33:00 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-10 18:33:00 +0200 |
| commit | 0fe218842e0e396e3ab3982bd21227968a9e7fd8 (patch) | |
| tree | 7e8ff33c5c282ffc91ed4f59ecf9dee7cbd35a3f /tests/backends/postgresql/test_compilation.py | |
| parent | 994950e886ea861aa862bff25a6865baa302bd32 (diff) | |
Fixed #36502 -- Restored UNNEST strategy for foreign key bulk inserts on PostgreSQL.
Regression in 764af7a3d6c0b543dcf659a2c327f214da768fe4.
Diffstat (limited to 'tests/backends/postgresql/test_compilation.py')
| -rw-r--r-- | tests/backends/postgresql/test_compilation.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/backends/postgresql/test_compilation.py b/tests/backends/postgresql/test_compilation.py index 5a86a427ff..275660607d 100644 --- a/tests/backends/postgresql/test_compilation.py +++ b/tests/backends/postgresql/test_compilation.py @@ -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] + ) |
