Author: jbronn
Date: 2010-07-20 14:05:46 -0500 (Tue, 20 Jul 2010)
New Revision: 13439
Modified:
django/trunk/django/contrib/gis/db/models/sql/compiler.py
django/trunk/django/contrib/gis/tests/relatedapp/models.py
django/trunk/django/contrib/gis/tests/relatedapp/tests.py
Log:
Fixed #13934 -- `GeoSQLCompiler.get_default_columns` was missing `local_only`
keyword argument. Thanks, Simon Law, for bug report and initial patch.
Modified: django/trunk/django/contrib/gis/db/models/sql/compiler.py
===================================================================
--- django/trunk/django/contrib/gis/db/models/sql/compiler.py 2010-07-19
21:04:03 UTC (rev 13438)
+++ django/trunk/django/contrib/gis/db/models/sql/compiler.py 2010-07-20
19:05:46 UTC (rev 13439)
@@ -95,7 +95,7 @@
return result
def get_default_columns(self, with_aliases=False, col_aliases=None,
- start_alias=None, opts=None, as_pairs=False):
+ start_alias=None, opts=None, as_pairs=False, local_only=False):
"""
Computes the default columns for selecting every field in the base
model. Will sometimes be called to pull in related models (e.g. via
@@ -121,6 +121,8 @@
if start_alias:
seen = {None: start_alias}
for field, model in opts.get_fields_with_model():
+ if local_only and model is not None:
+ continue
if start_alias:
try:
alias = seen[model]
Modified: django/trunk/django/contrib/gis/tests/relatedapp/models.py
===================================================================
--- django/trunk/django/contrib/gis/tests/relatedapp/models.py 2010-07-19
21:04:03 UTC (rev 13438)
+++ django/trunk/django/contrib/gis/tests/relatedapp/models.py 2010-07-20
19:05:46 UTC (rev 13439)
@@ -38,6 +38,11 @@
name = models.CharField(max_length=100)
objects = models.GeoManager()
+class Article(models.Model):
+ title = models.CharField(max_length=100)
+ author = models.ForeignKey(Author, unique=True)
+ objects = models.GeoManager()
+
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, related_name='books', null=True)
Modified: django/trunk/django/contrib/gis/tests/relatedapp/tests.py
===================================================================
--- django/trunk/django/contrib/gis/tests/relatedapp/tests.py 2010-07-19
21:04:03 UTC (rev 13438)
+++ django/trunk/django/contrib/gis/tests/relatedapp/tests.py 2010-07-20
19:05:46 UTC (rev 13439)
@@ -4,7 +4,7 @@
from django.contrib.gis.geometry.backend import Geometry
from django.contrib.gis.tests.utils import mysql, oracle, postgis, spatialite,
no_mysql, no_oracle, no_spatialite
from django.conf import settings
-from models import City, Location, DirectoryEntry, Parcel, Book, Author
+from models import City, Location, DirectoryEntry, Parcel, Book, Author,
Article
cities = (('Aurora', 'TX', -97.516111, 33.058333),
('Roswell', 'NM', -104.528056, 33.387222),
@@ -291,6 +291,14 @@
self.assertEqual(4, len(coll))
self.assertEqual(ref_geom, coll)
+ def test15_invalid_select_related(self):
+ "Testing doing select_related on the related name manager of a unique
FK. See #13934."
+ qs = Article.objects.select_related('author__article')
+ # This triggers TypeError when `get_default_columns` has no
`local_only`
+ # keyword. The TypeError is swallowed if QuerySet is actually
+ # evaluated as list generation swallows TypeError in CPython.
+ sql = str(qs.query)
+
# TODO: Related tests for KML, GML, and distance lookups.
def suite():
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.