mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #29568 -- Prevented unnecessary UPDATE queries creating child models.
This commit is contained in:
parent
65503ca097
commit
861638a307
2 changed files with 33 additions and 4 deletions
|
@ -133,6 +133,24 @@ class ModelInheritanceTests(TestCase):
|
|||
if 'UPDATE' in sql:
|
||||
self.assertEqual(expected_sql, sql)
|
||||
|
||||
def test_create_child_no_update(self):
|
||||
"""Creating a child with non-abstract parents only issues INSERTs."""
|
||||
def a():
|
||||
GrandChild.objects.create(
|
||||
email='grand_parent@example.com',
|
||||
first_name='grand',
|
||||
last_name='parent',
|
||||
)
|
||||
|
||||
def b():
|
||||
GrandChild().save()
|
||||
for i, test in enumerate([a, b]):
|
||||
with self.subTest(i=i), self.assertNumQueries(4), CaptureQueriesContext(connection) as queries:
|
||||
test()
|
||||
for query in queries:
|
||||
sql = query['sql']
|
||||
self.assertIn('INSERT INTO', sql, sql)
|
||||
|
||||
def test_eq(self):
|
||||
# Equality doesn't transfer in multitable inheritance.
|
||||
self.assertNotEqual(Place(id=1), Restaurant(id=1))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue