Re: [Django] #36093: Calling full_clean() on an existing child model instance in a multi-table inheritance should not execute a database query.

14 views
Skip to first unread message

Django

unread,
Jan 13, 2025, 11:14:25 AM1/13/25
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

> 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`

If that's truly the case (I haven't validated myself) it is a bug in
`pk_fields` itself.
--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 13, 2025, 11:20:40 AM1/13/25
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------
Comment (by Sage Abdullah):

Replying to [comment:3 Simon Charette]:
>
> If that's truly the case it is a bug in `pk_fields` itself.
>
> The one-to-one parent link seems to be in `pk_fields` though?
>
> {{{#!python
> >>> Restaurant._meta.pk_fields
> [<django.db.models.fields.related.OneToOneField: place_ptr>]
> }}}
>

Oops, yep, sorry – I was in a rush!

The `OneToOneField` is there, but the real PK in the parent model isn't.
--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:4>

Django

unread,
Jan 13, 2025, 11:24:30 AM1/13/25
to django-...@googlegroups.com
#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: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted

Comment:

Ahh I see. We should retrieve the `pk_fields` of all bases involved.
--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:5>

Django

unread,
Jan 13, 2025, 11:26:09 AM1/13/25
to django-...@googlegroups.com
#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: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

Does the following resolves the issue?

{{{#!diff
diff --git a/django/db/models/base.py b/django/db/models/base.py
index a4d5a0d553..0f07d235a9 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -1493,7 +1493,7 @@ def _perform_unique_checks(self, unique_checks):
):
# no value, skip the lookup
continue
- if f in self._meta.pk_fields and not self._state.adding:
+ if f in model_class._meta.pk_fields and not
self._state.adding:
# no need to check for unique primary key when
editing
continue
lookup_kwargs[str(field_name)] = lookup_value
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:6>

Django

unread,
Jan 13, 2025, 11:27:59 AM1/13/25
to django-...@googlegroups.com
#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: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sage Abdullah):

Replying to [comment:6 Simon Charette]:
> Does the following resolves the issue?

It does! Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:7>

Django

unread,
Jan 13, 2025, 1:59:00 PM1/13/25
to django-...@googlegroups.com
#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: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1
* owner: (none) => Simon Charette
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:8>

Django

unread,
Jan 14, 2025, 10:20:57 AM1/14/25
to django-...@googlegroups.com
#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: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:9>

Django

unread,
Jan 14, 2025, 10:21:39 AM1/14/25
to django-...@googlegroups.com
#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: Simon
| Charette
Type: Bug | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"4bfec242b488b174f7d386ab5bbd3363751cdb93" 4bfec242]:
{{{#!CommitTicketReference repository=""
revision="4bfec242b488b174f7d386ab5bbd3363751cdb93"
Fixed #36093 -- Adjusted unique checks to account for inherited primary
keys.

Regression in bf7b17d16d3978b2e1cee4a0f7ce8840bd1a8dc4 refs #36075.

Thanks Sage Abdullah for the report and tests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36093#comment:10>
Reply all
Reply to author
Forward
0 new messages