diff options
author | François Dupayrat <fradow@gmail.com> | 2018-07-20 14:59:15 +0200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-07-20 08:59:15 -0400 |
commit | 861638a3074f289faf729d739edf6326332a484f (patch) | |
tree | e2e4106306dd93cf0f0ade7d57d036d9e70f0065 /tests/model_inheritance | |
parent | 65503ca09798bffbe8226c3a8a7953906042b2ee (diff) | |
download | django-861638a3074f289faf729d739edf6326332a484f.tar.gz |
Fixed #29568 -- Prevented unnecessary UPDATE queries creating child models.
Diffstat (limited to 'tests/model_inheritance')
-rw-r--r-- | tests/model_inheritance/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index 7ab75b6cc3..4e8e92a60c 100644 --- a/tests/model_inheritance/tests.py +++ b/tests/model_inheritance/tests.py @@ -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)) |