Commit fdcc0c77 authored by Justin Bronn's avatar Justin Bronn
Browse files

Fixed #11381 -- `GeoManager` + `select_related` + nullable `ForeignKey` now...

Fixed #11381 -- `GeoManager` + `select_related` + nullable `ForeignKey` 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
parent 73530934
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ class GeoQuery(sql.Query):
                values.append(self.convert_values(value, field))
        else:
            values.extend(row[index_start:])
        return values
        return tuple(values)

    def convert_values(self, value, field):
        """
+1 −1
Original line number Diff line number Diff line
@@ -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()
+7 −0
Original line number Diff line number Diff line
@@ -257,6 +257,13 @@ class RelatedGeoModelTest(unittest.TestCase):
        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():