Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11381 -- `GeoManager` + `select_related` + nullable `ForeignKe…

…y` now works correctly. Thanks, bretthoerner for ticket and dgouldin for initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11123 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fdcc0c774a9295f5d0fa3a1edd34e4f7e41476d5 1 parent 7353093
Justin Bronn authored June 29, 2009
2  django/contrib/gis/db/models/sql/query.py
@@ -225,7 +225,7 @@ def resolve_columns(self, row, fields=()):
225 225
                 values.append(self.convert_values(value, field))
226 226
         else:
227 227
             values.extend(row[index_start:])
228  
-        return values
  228
+        return tuple(values)
229 229
 
230 230
     def convert_values(self, value, field):
231 231
         """
2  django/contrib/gis/tests/relatedapp/models.py
@@ -40,5 +40,5 @@ class Author(models.Model):
40 40
 
41 41
 class Book(models.Model):
42 42
     title = models.CharField(max_length=100)
43  
-    author = models.ForeignKey(Author, related_name='books')
  43
+    author = models.ForeignKey(Author, related_name='books', null=True)
44 44
     objects = models.GeoManager()
7  django/contrib/gis/tests/relatedapp/tests.py
@@ -257,6 +257,13 @@ def test12_count(self):
257 257
         self.assertEqual(1, len(qs))
258 258
         self.assertEqual(3, qs[0].num_books)
259 259
 
  260
+    def test13_select_related_null_fk(self):
  261
+        "Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
  262
+        no_author = Book.objects.create(title='Without Author')
  263
+        b = Book.objects.select_related('author').get(title='Without Author')
  264
+        # Should be `None`, and not a 'dummy' model.
  265
+        self.assertEqual(None, b.author)
  266
+
260 267
     # TODO: Related tests for KML, GML, and distance lookups.
261 268
 
262 269
 def suite():

0 notes on commit fdcc0c7

Please sign in to comment.
Something went wrong with that request. Please try again.