Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13934 -- `GeoSQLCompiler.get_default_columns` was missing `loc…

…al_only` keyword argument. Thanks, Simon Law, for bug report and initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13439 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 87a60e28cc6a0127c798af9b20ac4e891f082ebc 1 parent 2fce843
Justin Bronn authored July 20, 2010
4  django/contrib/gis/db/models/sql/compiler.py
@@ -95,7 +95,7 @@ def get_columns(self, with_aliases=False):
95 95
         return result
96 96
 
97 97
     def get_default_columns(self, with_aliases=False, col_aliases=None,
98  
-                            start_alias=None, opts=None, as_pairs=False):
  98
+            start_alias=None, opts=None, as_pairs=False, local_only=False):
99 99
         """
100 100
         Computes the default columns for selecting every field in the base
101 101
         model. Will sometimes be called to pull in related models (e.g. via
@@ -121,6 +121,8 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
121 121
         if start_alias:
122 122
             seen = {None: start_alias}
123 123
         for field, model in opts.get_fields_with_model():
  124
+            if local_only and model is not None:
  125
+                continue
124 126
             if start_alias:
125 127
                 try:
126 128
                     alias = seen[model]
5  django/contrib/gis/tests/relatedapp/models.py
@@ -38,6 +38,11 @@ class Author(models.Model):
38 38
     name = models.CharField(max_length=100)
39 39
     objects = models.GeoManager()
40 40
 
  41
+class Article(models.Model):
  42
+    title = models.CharField(max_length=100)
  43
+    author = models.ForeignKey(Author, unique=True)
  44
+    objects = models.GeoManager()
  45
+
41 46
 class Book(models.Model):
42 47
     title = models.CharField(max_length=100)
43 48
     author = models.ForeignKey(Author, related_name='books', null=True)
10  django/contrib/gis/tests/relatedapp/tests.py
@@ -4,7 +4,7 @@
4 4
 from django.contrib.gis.geometry.backend import Geometry
5 5
 from django.contrib.gis.tests.utils import mysql, oracle, postgis, spatialite, no_mysql, no_oracle, no_spatialite
6 6
 from django.conf import settings
7  
-from models import City, Location, DirectoryEntry, Parcel, Book, Author
  7
+from models import City, Location, DirectoryEntry, Parcel, Book, Author, Article
8 8
 
9 9
 cities = (('Aurora', 'TX', -97.516111, 33.058333),
10 10
           ('Roswell', 'NM', -104.528056, 33.387222),
@@ -291,6 +291,14 @@ def test14_collect(self):
291 291
             self.assertEqual(4, len(coll))
292 292
             self.assertEqual(ref_geom, coll)
293 293
 
  294
+    def test15_invalid_select_related(self):
  295
+        "Testing doing select_related on the related name manager of a unique FK. See #13934."
  296
+        qs = Article.objects.select_related('author__article')
  297
+        # This triggers TypeError when `get_default_columns` has no `local_only`
  298
+        # keyword.  The TypeError is swallowed if QuerySet is actually
  299
+        # evaluated as list generation swallows TypeError in CPython.
  300
+        sql = str(qs.query)
  301
+        
294 302
     # TODO: Related tests for KML, GML, and distance lookups.
295 303
 
296 304
 def suite():

0 notes on commit 87a60e2

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