Code

Ticket #13987: 13987_fix_2_with_tests_updated.diff

File 13987_fix_2_with_tests_updated.diff, 3.0 KB (added by Aramgutang, 4 years ago)

Updated patch to bring test into line with the changes in the test suite.

Line 
1Index: django/db/models/options.py
2===================================================================
3--- django/db/models/options.py (revision 14787)
4+++ django/db/models/options.py (working copy)
5@@ -119,6 +119,9 @@
6                 # Promote the first parent link in lieu of adding yet another
7                 # field.
8                 field = self.parents.value_for_index(0)
9+                already_created = [fld for fld in self.local_fields if fld.name == field.name]
10+                if already_created:
11+                    field = already_created[0]
12                 field.primary_key = True
13                 self.setup_pk(field)
14             else:
15Index: tests/regressiontests/model_inheritance_regress/tests.py
16===================================================================
17--- tests/regressiontests/model_inheritance_regress/tests.py    (revision 14787)
18+++ tests/regressiontests/model_inheritance_regress/tests.py    (working copy)
19@@ -11,7 +11,7 @@
20     ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
21     SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM,
22     Person, BirthdayParty, BachelorParty, MessyBachelorParty,
23-    InternalCertificationAudit)
24+    InternalCertificationAudit, BusStation, TrainStation)
25 
26 
27 class ModelInheritanceTest(TestCase):
28@@ -386,3 +386,23 @@
29             ],
30             attrgetter("pk")
31         )
32+   
33+    def test_13987(self):
34+        """
35+        Primary key set correctly with concrete->abstract->concrete inheritance.
36+        """
37+        # Regression test for #13987: Primary key is incorrectly determined
38+        # when more than one model has a concrete->abstract->concrete
39+        # inheritance hierarchy.
40+        self.assertEquals(
41+            len([field for field in BusStation._meta.local_fields
42+                       if field.primary_key]),
43+            1
44+        )
45+        self.assertEquals(
46+            len([field for field in TrainStation._meta.local_fields
47+                       if field.primary_key]),
48+            1
49+        )
50+        self.assertIs(BusStation._meta.pk.model, BusStation)
51+        self.assertIs(TrainStation._meta.pk.model, TrainStation)
52Index: tests/regressiontests/model_inheritance_regress/models.py
53===================================================================
54--- tests/regressiontests/model_inheritance_regress/models.py   (revision 14787)
55+++ tests/regressiontests/model_inheritance_regress/models.py   (working copy)
56@@ -146,3 +146,20 @@
57 
58 class MessyBachelorParty(BachelorParty):
59     pass
60+
61+# Check concrete -> abstract -> concrete inheritance
62+class SearchableLocation(models.Model):
63+    keywords = models.CharField(max_length=256)
64+
65+class Station(SearchableLocation):
66+    name = models.CharField(max_length=128)
67+   
68+    class Meta:
69+        abstract = True
70+
71+class BusStation(Station):
72+    bus_routes = models.CommaSeparatedIntegerField(max_length=128)
73+    inbound = models.BooleanField()
74+
75+class TrainStation(Station):
76+    zone = models.IntegerField()