Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@jbronn jbronn authored
View
2  django/contrib/gis/db/models/sql/query.py
@@ -225,7 +225,7 @@ def resolve_columns(self, row, fields=()):
values.append(self.convert_values(value, field))
else:
values.extend(row[index_start:])
- return values
+ return tuple(values)
def convert_values(self, value, field):
"""
View
2  django/contrib/gis/tests/relatedapp/models.py
@@ -40,5 +40,5 @@ class Author(models.Model):
class Book(models.Model):
title = models.CharField(max_length=100)
- author = models.ForeignKey(Author, related_name='books')
+ author = models.ForeignKey(Author, related_name='books', null=True)
objects = models.GeoManager()
View
7 django/contrib/gis/tests/relatedapp/tests.py
@@ -257,6 +257,13 @@ def test12_count(self):
self.assertEqual(1, len(qs))
self.assertEqual(3, qs[0].num_books)
+ def test13_select_related_null_fk(self):
+ "Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
+ no_author = Book.objects.create(title='Without Author')
+ b = Book.objects.select_related('author').get(title='Without Author')
+ # Should be `None`, and not a 'dummy' model.
+ self.assertEqual(None, b.author)
+
# TODO: Related tests for KML, GML, and distance lookups.
def suite():

0 comments on commit fdcc0c7

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