[1.11.x] Fixed #27603 -- Fixed AsKML when queryset is evaluated more than once.

Backport of e9149d3eb0 from master
This commit is contained in:
Sergey Fedoseev 2017-03-23 23:27:13 +05:00 committed by Tim Graham
parent a8c540accc
commit b6a6787fd8
2 changed files with 7 additions and 3 deletions

View File

@ -196,8 +196,9 @@ class AsGML(GeoFunc):
class AsKML(AsGML): class AsKML(AsGML):
def as_sqlite(self, compiler, connection): def as_sqlite(self, compiler, connection):
# No version parameter # No version parameter
self.source_expressions.pop(0) clone = self.copy()
return super(AsKML, self).as_sql(compiler, connection) clone.set_source_expressions(self.get_source_expressions()[1:])
return clone.as_sql(compiler, connection)
class AsSVG(GeoFunc): class AsSVG(GeoFunc):

View File

@ -122,8 +122,11 @@ class GISFunctionsTests(TestCase):
City.objects.annotate(kml=functions.AsKML('name')) City.objects.annotate(kml=functions.AsKML('name'))
# Ensuring the KML is as expected. # Ensuring the KML is as expected.
ptown = City.objects.annotate(kml=functions.AsKML('point', precision=9)).get(name='Pueblo') qs = City.objects.annotate(kml=functions.AsKML('point', precision=9))
ptown = qs.get(name='Pueblo')
self.assertEqual('<Point><coordinates>-104.609252,38.255001</coordinates></Point>', ptown.kml) self.assertEqual('<Point><coordinates>-104.609252,38.255001</coordinates></Point>', ptown.kml)
# Same result if the queryset is evaluated again.
self.assertEqual(qs.get(name='Pueblo').kml, ptown.kml)
@skipUnlessDBFeature("has_AsSVG_function") @skipUnlessDBFeature("has_AsSVG_function")
def test_assvg(self): def test_assvg(self):