Opened 42 hours ago

Last modified 18 hours ago

#36093 closed Bug

Calling full_clean() on an existing child model instance in a multi-table inheritance should not execute a database query. — at Version 2

Reported by: Sage Abdullah Owned by:
Component: Database layer (models, ORM) Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Sage Abdullah)

Regression in bf7b17d16d3978b2e1cee4a0f7ce8840bd1a8dc4.

The following test now fails after the above commit:

diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py
index 6b005fcef0..28d03e1687 100644
--- a/tests/model_inheritance/tests.py
+++ b/tests/model_inheritance/tests.py
@@ -343,6 +343,12 @@ class ModelInheritanceTests(TestCase):

         self.assertEqual(type(MethodOverride.foo), DeferredAttribute)

+    def test_full_clean(self):
+        restaurant = Restaurant.objects.create()
+        with self.assertNumQueries(0):
+            with self.assertRaises(ValidationError):
+                restaurant.full_clean()
+

 class ModelInheritanceDataTests(TestCase):
     @classmethod

This is because the primary key of a child model is a OneToOneField to the parent model (e.g. place_ptr), and it's not in pk_fields, so the changes to the check for skipping primary key when editing no longer passes for child models.

The exact query can be seen in my repro example.

Change History (2)

comment:1 by Sage Abdullah, 42 hours ago

I have a sneaking suspicion that the problem may also manifest in the other areas affected by the commit, e.g. bulk_update. I have yet to confirm it, though.

If handling this requires some additional logic to check whether a field is a primary key beyond checking its existence in _meta.pk_fields, we might need to have a dedicated method for it and use it everywhere.

comment:2 by Sage Abdullah, 42 hours ago

Description: modified (diff)
Summary: Calling `full_clean()` on an existing child model instance in a multi-table inheritance should not execute a database query.Calling full_clean() on an existing child model instance in a multi-table inheritance should not execute a database query.
Note: See TracTickets for help on using tickets.
Back to Top