Code

Ticket #12240: django-12240.diff

File django-12240.diff, 2.2 KB (added by embe, 5 years ago)
Line 
1Index: django/db/models/sql/query.py
2===================================================================
3--- django/db/models/sql/query.py       (revision 11910)
4+++ django/db/models/sql/query.py       (working copy)
5@@ -1436,14 +1436,10 @@
6                 next = requested.get(f.name, {})
7             else:
8                 next = False
9-            if f.null is not None:
10-                new_nullable = f.null
11-            else:
12-                new_nullable = None
13             for dupe_opts, dupe_col in dupe_set:
14                 self.update_dupe_avoidance(dupe_opts, dupe_col, alias)
15             self.fill_related_selections(f.rel.to._meta, alias, cur_depth + 1,
16-                    used, next, restricted, new_nullable, dupe_set, avoid)
17+                    used, next, restricted, promote, dupe_set, avoid)
18 
19     def add_aggregate(self, aggregate, model, alias, is_summary):
20         """
21Index: tests/regressiontests/null_fk/models.py
22===================================================================
23--- tests/regressiontests/null_fk/models.py     (revision 11910)
24+++ tests/regressiontests/null_fk/models.py     (working copy)
25@@ -4,7 +4,11 @@
26 
27 from django.db import models
28 
29+class SystemDetails(models.Model):
30+    details = models.CharField(max_length=32)
31+
32 class SystemInfo(models.Model):
33+    system_details = models.ForeignKey(SystemDetails)
34     system_name = models.CharField(max_length=32)
35 
36 class Forum(models.Model):
37@@ -30,7 +34,8 @@
38 
39 __test__ = {'API_TESTS':"""
40 
41->>> s = SystemInfo.objects.create(system_name='First forum')
42+>>> d = SystemDetails.objects.create(details='First details')
43+>>> s = SystemInfo.objects.create(system_details=d, system_name='First forum')
44 >>> f = Forum.objects.create(system_info=s, forum_name='First forum')
45 >>> p = Post.objects.create(forum=f, title='First Post')
46 >>> c1 = Comment.objects.create(post=p, comment_text='My first comment')
47@@ -55,4 +60,9 @@
48 >>> Comment.objects.select_related('post').filter(post__isnull=True)[0].post is None
49 True
50 
51+# Regression test for #12240.
52+>>> comments = Comment.objects.select_related('post__forum__system_info__system_details').all()
53+>>> [(c.id, c.comment_text, c.post) for c in comments]
54+[(1, u'My first comment', <Post: First Post>), (2, u'My second comment', None)]
55+
56 """}