1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #35890 -- Fixed custom pre_save in fields from parents models not being called.

This commit is contained in:
Gagaro 2024-11-06 15:34:27 +01:00
parent c2c544cf01
commit a6687ed025
3 changed files with 10 additions and 3 deletions

View File

@ -992,7 +992,7 @@ class QuerySet(AltersData):
# This is to maintain backward compatibility as these fields # This is to maintain backward compatibility as these fields
# are not updated unless explicitly specified in the # are not updated unless explicitly specified in the
# update_fields list. # update_fields list.
for field in self.model._meta.local_concrete_fields: for field in self.model._meta.concrete_fields:
if not ( if not (
field.primary_key or field.__class__.pre_save is Field.pre_save field.primary_key or field.__class__.pre_save is Field.pre_save
): ):

View File

@ -65,3 +65,7 @@ class Book(models.Model):
db_column="publisher_id_column", db_column="publisher_id_column",
) )
updated = models.DateTimeField(auto_now=True) updated = models.DateTimeField(auto_now=True)
class ComicBook(Book):
pass

View File

@ -12,6 +12,7 @@ from django.utils.functional import lazy
from .models import ( from .models import (
Author, Author,
Book, Book,
ComicBook,
DefaultPerson, DefaultPerson,
Journalist, Journalist,
ManualPrimaryKeyTest, ManualPrimaryKeyTest,
@ -579,12 +580,14 @@ class UpdateOrCreateTests(TestCase):
def test_update_only_defaults_and_pre_save_fields_when_local_fields(self): def test_update_only_defaults_and_pre_save_fields_when_local_fields(self):
publisher = Publisher.objects.create(name="Acme Publishing") publisher = Publisher.objects.create(name="Acme Publishing")
book = Book.objects.create(publisher=publisher, name="The Book of Ed & Fred") book = ComicBook.objects.create(
publisher=publisher, name="The Book of Ed & Fred"
)
for defaults in [{"publisher": publisher}, {"publisher_id": publisher}]: for defaults in [{"publisher": publisher}, {"publisher_id": publisher}]:
with self.subTest(defaults=defaults): with self.subTest(defaults=defaults):
with CaptureQueriesContext(connection) as captured_queries: with CaptureQueriesContext(connection) as captured_queries:
book, created = Book.objects.update_or_create( book, created = ComicBook.objects.update_or_create(
pk=book.pk, pk=book.pk,
defaults=defaults, defaults=defaults,
) )