Opened 18 months ago
Last modified 17 months ago
#34634 closed Bug
Creating objects with nested MTI crashes. — at Version 1
Reported by: | Mariusz Felisiak | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.2 |
Severity: | Normal | Keywords: | |
Cc: | Simon Charette, David Sanders, Lily Foote | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Checking PR I noticed that creating objects with more complicated multi-table inheritance crashes. For example:
-
tests/model_inheritance/models.py
diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py index dc0e238f7e..d75df0d533 100644
a b class ItalianRestaurant(Restaurant): 106 106 serves_gnocchi = models.BooleanField(default=False) 107 107 108 108 109 class ItalianRestaurantManyParents(ItalianRestaurant, Place): 110 pass 111 112 109 113 class Supplier(Place): 110 114 customers = models.ManyToManyField(Restaurant, related_name="provider") 111 115 -
tests/model_inheritance/tests.py
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index 4542e6c3cc..838d35b9d6 100644
a b from .models import ( 14 14 GrandChild, 15 15 GrandParent, 16 16 ItalianRestaurant, 17 ItalianRestaurantManyParents, 17 18 MixinModel, 18 19 Parent, 19 20 ParkingLot, … … class ModelInheritanceTests(TestCase): 149 150 # accidentally found). 150 151 self.assertSequenceEqual(s.titles.all(), []) 151 152 153 def test_create_diamond_mti_common_parents(self): 154 with self.assertNumQueries(4): 155 ItalianRestaurantManyParents.objects.create( 156 name="Ristorante Miron", 157 address="1234 W. Ash", 158 ) 159 152 160 def test_update_parent_filtering(self): 153 161 """ 154 162 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'
Change History (2)
by , 18 months ago
Attachment: | Screenshot_20230606_091439.png added |
---|
comment:1 by , 18 months ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.