diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py index 4f3c08a4b07..542cafb6bda 100644 --- a/django/db/models/fields/related_descriptors.py +++ b/django/db/models/fields/related_descriptors.py @@ -272,6 +272,7 @@ class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor): if not any(field in fields for field in deferred): kwargs = {field: getattr(instance, field) for field in fields} obj = rel_model(**kwargs) + obj._state.adding = instance._state.adding obj._state.db = instance._state.db return obj return super().get_object(instance) diff --git a/docs/releases/1.11.2.txt b/docs/releases/1.11.2.txt index 8d82581966a..a15d4272ec2 100644 --- a/docs/releases/1.11.2.txt +++ b/docs/releases/1.11.2.txt @@ -25,3 +25,7 @@ Bugfixes backends don't accept a positional ``request`` argument (:ticket:`28207`). * Fixed introspection of index field ordering on PostgreSQL (:ticket:`28197`). + +* Fixed a regression where ``Model._state.adding`` wasn't set correctly on + multi-table inheritance parent models after saving a child model + (:ticket:`28210`). diff --git a/tests/model_inheritance_regress/tests.py b/tests/model_inheritance_regress/tests.py index 0ecaedd0909..7ed84cc5d02 100644 --- a/tests/model_inheritance_regress/tests.py +++ b/tests/model_inheritance_regress/tests.py @@ -478,8 +478,9 @@ class ModelInheritanceTest(TestCase): # The mismatch between Restaurant and Place is intentional (#28175). self.assertSequenceEqual(Supplier.objects.filter(restaurant__in=Place.objects.all()), [s]) - def test_ptr_accessor_assigns_db(self): + def test_ptr_accessor_assigns_state(self): r = Restaurant.objects.create() + self.assertIs(r.place_ptr._state.adding, False) self.assertEqual(r.place_ptr._state.db, 'default') def test_related_filtering_query_efficiency_ticket_15844(self):