﻿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
34634	Creating objects with nested MTI crashes.	Mariusz Felisiak	Akash Kumar Sen	"Checking [https://github.com/django/django/pull/16903 PR] I noticed that creating objects with more complicated multi-table inheritance crashes. For example:
[[Image(Screenshot_20230606_091439.png)]]
{{{#!diff
diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py
index dc0e238f7e..d75df0d533 100644
--- a/tests/model_inheritance/models.py
+++ b/tests/model_inheritance/models.py
@@ -106,6 +106,10 @@ class ItalianRestaurant(Restaurant):
     serves_gnocchi = models.BooleanField(default=False)
 
 
+class ItalianRestaurantManyParents(ItalianRestaurant, Place):
+    pass
+
+
 class Supplier(Place):
     customers = models.ManyToManyField(Restaurant, related_name=""provider"")
 
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py
index 4542e6c3cc..838d35b9d6 100644
--- a/tests/model_inheritance/tests.py
+++ b/tests/model_inheritance/tests.py
@@ -14,6 +14,7 @@ from .models import (
     GrandChild,
     GrandParent,
     ItalianRestaurant,
+    ItalianRestaurantManyParents,
     MixinModel,
     Parent,
     ParkingLot,
@@ -149,6 +150,13 @@ class ModelInheritanceTests(TestCase):
         # accidentally found).
         self.assertSequenceEqual(s.titles.all(), [])
 
+    def test_create_diamond_mti_common_parents(self):
+        with self.assertNumQueries(4):
+            ItalianRestaurantManyParents.objects.create(
+                name=""Ristorante Miron"",
+                address=""1234 W. Ash"",
+            )
+
     def test_update_parent_filtering(self):
         """"""
         Updating a field of a model subclass doesn't issue an UPDATE
}}}

crashes with:

{{{
  File ""/django/tests/model_inheritance/tests.py"", line 155, in test_create_diamond_mti_common_parents
    ItalianRestaurantManyParents.objects.create(
  File ""/django/django/db/models/manager.py"", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File ""/django/django/db/models/query.py"", line 650, in create
    obj.save(force_insert=True, using=self.db)
  File ""/django/django/db/models/base.py"", line 814, in save
    self.save_base(
  File ""/django/django/db/models/base.py"", line 876, in save_base
    parent_inserted = self._save_parents(cls, using, update_fields)
  File ""/django/django/db/models/base.py"", line 928, in _save_parents
    setattr(self, field.attname, self._get_pk_val(parent._meta))
AttributeError: 'OneToOneField' object has no attribute 'attname'
}}}"	Bug	closed	Database layer (models, ORM)	4.2	Normal	fixed		Simon Charette David Sanders Lily Foote	Ready for checkin	1	0	0	0	0	0
