mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #18432 -- Prevented the ForeignKey field from creating an invalid query when chained. Thanks, Jann Kleen.
This commit is contained in:
committed by
Jannis Leidel
parent
5e6ded2e58
commit
1a412dda62
@@ -8,8 +8,7 @@ from django.test import TestCase, skipUnlessDBFeature
|
||||
from django.utils import tzinfo
|
||||
|
||||
from .models import (Worker, Article, Party, Event, Department,
|
||||
BrokenUnicodeMethod, NonAutoPK)
|
||||
|
||||
BrokenUnicodeMethod, NonAutoPK, Model1, Model2, Model3)
|
||||
|
||||
|
||||
class ModelTests(TestCase):
|
||||
@@ -47,7 +46,7 @@ class ModelTests(TestCase):
|
||||
a = Article.objects.create(
|
||||
headline="Really, really big",
|
||||
pub_date=datetime.datetime.now(),
|
||||
article_text = "ABCDE" * 1000
|
||||
article_text="ABCDE" * 1000
|
||||
)
|
||||
a = Article.objects.get(pk=a.pk)
|
||||
self.assertEqual(len(a.article_text), 5000)
|
||||
@@ -164,6 +163,19 @@ class ModelTests(TestCase):
|
||||
1
|
||||
)
|
||||
|
||||
def test_chained_fks(self):
|
||||
"""
|
||||
Regression for #18432: Chained foreign keys with to_field produce incorrect query
|
||||
"""
|
||||
|
||||
m1 = Model1.objects.create(pkey=1000)
|
||||
m2 = Model2.objects.create(model1=m1)
|
||||
m3 = Model3.objects.create(model2=m2)
|
||||
|
||||
# this is the actual test for #18432
|
||||
m3 = Model3.objects.get(model2=1000)
|
||||
m3.model2
|
||||
|
||||
|
||||
class ModelValidationTest(TestCase):
|
||||
def test_pk_validation(self):
|
||||
|
||||
Reference in New Issue
Block a user