Fixed #29568 -- Prevented unnecessary UPDATE queries creating child models.

This commit is contained in:
François Dupayrat 2018-07-20 14:59:15 +02:00 committed by Tim Graham
parent 65503ca097
commit 861638a307
2 changed files with 33 additions and 4 deletions

View file

@ -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))