Fixed #11489 -- `GeoQuery.resolve_columns` now recognizes annotations; disabled problematic test cases on Oracle and added notes on why.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11251 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8d48eaa064
commit
53b8809277
|
@ -13,7 +13,9 @@ from django.contrib.gis.measure import Area, Distance
|
||||||
ALL_TERMS = sql.constants.QUERY_TERMS.copy()
|
ALL_TERMS = sql.constants.QUERY_TERMS.copy()
|
||||||
ALL_TERMS.update(SpatialBackend.gis_terms)
|
ALL_TERMS.update(SpatialBackend.gis_terms)
|
||||||
|
|
||||||
|
# Pulling out other needed constants/routines to avoid attribute lookups.
|
||||||
TABLE_NAME = sql.constants.TABLE_NAME
|
TABLE_NAME = sql.constants.TABLE_NAME
|
||||||
|
get_proxied_model = sql.query.get_proxied_model
|
||||||
|
|
||||||
class GeoQuery(sql.Query):
|
class GeoQuery(sql.Query):
|
||||||
"""
|
"""
|
||||||
|
@ -153,7 +155,9 @@ class GeoQuery(sql.Query):
|
||||||
opts = self.model._meta
|
opts = self.model._meta
|
||||||
aliases = set()
|
aliases = set()
|
||||||
only_load = self.deferred_to_columns()
|
only_load = self.deferred_to_columns()
|
||||||
proxied_model = opts.proxy and opts.proxy_for_model or 0
|
# Skip all proxy to the root proxied model
|
||||||
|
proxied_model = get_proxied_model(opts)
|
||||||
|
|
||||||
if start_alias:
|
if start_alias:
|
||||||
seen = {None: start_alias}
|
seen = {None: start_alias}
|
||||||
for field, model in opts.get_fields_with_model():
|
for field, model in opts.get_fields_with_model():
|
||||||
|
@ -205,6 +209,10 @@ class GeoQuery(sql.Query):
|
||||||
"""
|
"""
|
||||||
values = []
|
values = []
|
||||||
aliases = self.extra_select.keys()
|
aliases = self.extra_select.keys()
|
||||||
|
if self.aggregates:
|
||||||
|
# If we have an aggregate annotation, must extend the aliases
|
||||||
|
# so their corresponding row values are included.
|
||||||
|
aliases.extend([None for i in xrange(len(self.aggregates))])
|
||||||
|
|
||||||
# Have to set a starting row number offset that is used for
|
# Have to set a starting row number offset that is used for
|
||||||
# determining the correct starting row index -- needed for
|
# determining the correct starting row index -- needed for
|
||||||
|
|
|
@ -231,8 +231,12 @@ class RelatedGeoModelTest(unittest.TestCase):
|
||||||
q = pickle.loads(q_str)
|
q = pickle.loads(q_str)
|
||||||
self.assertEqual(GeoQuery, q.__class__)
|
self.assertEqual(GeoQuery, q.__class__)
|
||||||
|
|
||||||
def test12_count(self):
|
# TODO: fix on Oracle -- get the following error because the SQL is ordered
|
||||||
"Testing `Count` aggregate use with the `GeoManager`. See #11087."
|
# by a geometry object, which Oracle apparently doesn't like:
|
||||||
|
# ORA-22901: cannot compare nested table or VARRAY or LOB attributes of an object type
|
||||||
|
@no_oracle
|
||||||
|
def test12a_count(self):
|
||||||
|
"Testing `Count` aggregate use with the `GeoManager` on geo-fields."
|
||||||
# Creating a new City, 'Fort Worth', that uses the same location
|
# Creating a new City, 'Fort Worth', that uses the same location
|
||||||
# as Dallas.
|
# as Dallas.
|
||||||
dallas = City.objects.get(name='Dallas')
|
dallas = City.objects.get(name='Dallas')
|
||||||
|
@ -242,6 +246,8 @@ class RelatedGeoModelTest(unittest.TestCase):
|
||||||
loc = Location.objects.annotate(num_cities=Count('city')).get(id=dallas.location.id)
|
loc = Location.objects.annotate(num_cities=Count('city')).get(id=dallas.location.id)
|
||||||
self.assertEqual(2, loc.num_cities)
|
self.assertEqual(2, loc.num_cities)
|
||||||
|
|
||||||
|
def test12b_count(self):
|
||||||
|
"Testing `Count` aggregate use with the `GeoManager` on non geo-fields. See #11087."
|
||||||
# Creating some data for the Book/Author non-geo models that
|
# Creating some data for the Book/Author non-geo models that
|
||||||
# use GeoManager. See #11087.
|
# use GeoManager. See #11087.
|
||||||
tp = Author.objects.create(name='Trevor Paglen')
|
tp = Author.objects.create(name='Trevor Paglen')
|
||||||
|
@ -250,13 +256,19 @@ class RelatedGeoModelTest(unittest.TestCase):
|
||||||
Book.objects.create(title='Blank Spots on the Map', author=tp)
|
Book.objects.create(title='Blank Spots on the Map', author=tp)
|
||||||
wp = Author.objects.create(name='William Patry')
|
wp = Author.objects.create(name='William Patry')
|
||||||
Book.objects.create(title='Patry on Copyright', author=wp)
|
Book.objects.create(title='Patry on Copyright', author=wp)
|
||||||
|
|
||||||
# Should only be one author (Trevor Paglen) returned by this query, and
|
# Should only be one author (Trevor Paglen) returned by this query, and
|
||||||
# the annotation should have 3 for the number of books.
|
# the annotation should have 3 for the number of books. Also testing
|
||||||
|
# with a `GeoValuesQuerySet` (see #11489).
|
||||||
qs = Author.objects.annotate(num_books=Count('books')).filter(num_books__gt=1)
|
qs = Author.objects.annotate(num_books=Count('books')).filter(num_books__gt=1)
|
||||||
|
vqs = Author.objects.values('name').annotate(num_books=Count('books')).filter(num_books__gt=1)
|
||||||
self.assertEqual(1, len(qs))
|
self.assertEqual(1, len(qs))
|
||||||
self.assertEqual(3, qs[0].num_books)
|
self.assertEqual(3, qs[0].num_books)
|
||||||
|
self.assertEqual(1, len(vqs))
|
||||||
|
self.assertEqual(3, vqs[0]['num_books'])
|
||||||
|
|
||||||
|
# TODO: The phantom model does appear on Oracle.
|
||||||
|
@no_oracle
|
||||||
def test13_select_related_null_fk(self):
|
def test13_select_related_null_fk(self):
|
||||||
"Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
|
"Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
|
||||||
no_author = Book.objects.create(title='Without Author')
|
no_author = Book.objects.create(title='Without Author')
|
||||||
|
|
Loading…
Reference in New Issue