1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #31002 -- Fixed GIS lookups crash against a subquery annotation.

Thanks Vasileios Bouzas for the report.
This commit is contained in:
Simon Charette
2019-11-24 10:21:32 -05:00
committed by Mariusz Felisiak
parent 29d8198841
commit 0290e01d5a
3 changed files with 22 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ from django.contrib.gis.geos import (
)
from django.core.management import call_command
from django.db import NotSupportedError, connection
from django.db.models import F, OuterRef, Subquery
from django.test import TestCase, skipUnlessDBFeature
from ..utils import (
@@ -17,8 +18,8 @@ from ..utils import (
spatialite,
)
from .models import (
City, Country, Feature, MinusOneSRID, NonConcreteModel, PennsylvaniaCity,
State, Track,
City, Country, Feature, MinusOneSRID, MultiFields, NonConcreteModel,
PennsylvaniaCity, State, Track,
)
@@ -494,6 +495,21 @@ class GeoLookupTest(TestCase):
with self.subTest(lookup):
City.objects.filter(**{'point__' + lookup: functions.Union('point', 'point')}).exists()
def test_subquery_annotation(self):
multifields = MultiFields.objects.create(
city=City.objects.create(point=Point(1, 1)),
point=Point(2, 2),
poly=Polygon.from_bbox((0, 0, 2, 2)),
)
qs = MultiFields.objects.annotate(
city_point=Subquery(City.objects.filter(
id=OuterRef('city'),
).values('point')),
).filter(
city_point__within=F('poly'),
)
self.assertEqual(qs.get(), multifields)
class GeoQuerySetTest(TestCase):
# TODO: GeoQuerySet is removed, organize these test better.