﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35125	Parent model fields are ignored when preparing the update_fields	Gustavo Silva	nobody	"Hi all,

This might be an edge case but I'd like to report this functionality that might be slightly broken, as someone coming from Django 3.X to Django 4.X.

According to [https://docs.djangoproject.com/en/4.2/ref/models/fields/#django.db.models.DateField.auto_now 4.2 the docs], using `auto_now` in model fields might not result in actual updates after the `save()` method is called.

However, the code has a piece for backward compatibility, where these fields are indeed picked up:
https://github.com/django/django/blob/4.2.3/django/db/models/query.py#L959-962

This raises the first problem, which is the inconsistency between documentation and the actual code. I appreciate the backward compatibility though, it's a lifesaver for my specific use case :)

The other issue I am having is with a potentially unusual model scheme where I have parent classes for some models. These are not abstract classes, but sorts of aggregator classes:

{{{
class A(model.Model):
    updated_at = models.DateTimeField(auto_now=True)
    something = models.BooleanField(default=True)

# in another app
class B(A):
    name = models.CharField()
}}}

Previously, when we did `B.objects.update_or_create(name=""x"", defaults={""something"": False})` it would automatically update `updated_at` timestamp. In 4.2 (and above, apparently) this is no longer happening. **However**, if `updated_at` was a field in the `B` class, `updated_at` would be picked up for update with the same `update_or_create` call. Notice I do not need to specify the `updated_at` field.

My workaround for now will be to override the save method of the parent classes to include the `updated_at` field in the `update_fields` list.


[https://github.com/django/django/blob/4.2.3/django/db/models/query.py#L963 when line 963 of the query] is called it only uses the local model fields to prepare the new `update_fields`. This drops any field coming from the parent class.


----


I'd like to propose to use `self.model._meta._non_pk_concrete_field_names` instead of `self.model_meta.local_concrete_fields` in the above line of code, or any other attribute that contains the parent fields that its better suited. If this is accepted as an issue, I can create a patch and submit it for review/approval.

Django version: 4.2.3
Python: 3.11.1

This is the first time I am contributing to Django - I apologise if there is a better way to report issues or if there are any templates to follow.

Feel free to ask any question or ask for what is not clear in this description.

Thanks in advance."	New feature	closed	Database layer (models, ORM)	4.2	Normal	needsinfo	update_or_create		Unreviewed	0	0	0	0	0	0
