#36093: Calling full_clean() on an existing child model instance in a
multi-table
inheritance should not execute a database query.
-------------------------------------+-------------------------------------
Reporter: Sage Abdullah | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sage Abdullah):
* 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.
Old description:
> 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
> [https://github.com/django/django/blob/bf7b17d16d3978b2e1cee4a0f7ce8840bd1a8dc4/django/db/models/base.py#L1496-L1498
> the check for the check for skipping primary key when editing] no longer
> passes for child models.
New description:
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
[https://github.com/django/django/blob/bf7b17d16d3978b2e1cee4a0f7ce8840bd1a8dc4/django/db/models/base.py#L1496-L1498
the check for skipping primary key when editing] no longer passes for
child models.
The exact query can be seen in [https://github.com/laymonage/django-
fullclean-repro/actions/runs/12750852443/job/35536526461 my repro
example].
--
--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070194606d6f45-077b2b1b-9ce8-41c0-ac2b-754fcde18692-000000%40eu-central-1.amazonses.com.