Skip to content

Commit e9149d3

Browse files
sir-sigurdtimgraham
authored andcommitted
Fixed #27603 -- Fixed AsKML when queryset is evaluated more than once.
1 parent 7e09fa7 commit e9149d3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

django/contrib/gis/db/models/functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ def as_oracle(self, compiler, connection, **extra_context):
195195
class AsKML(AsGML):
196196
def as_sqlite(self, compiler, connection):
197197
# No version parameter
198-
self.source_expressions.pop(0)
199-
return super().as_sql(compiler, connection)
198+
clone = self.copy()
199+
clone.set_source_expressions(self.get_source_expressions()[1:])
200+
return clone.as_sql(compiler, connection)
200201

201202

202203
class AsSVG(GeoFunc):

tests/gis_tests/geoapp/test_functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ def test_askml(self):
118118
City.objects.annotate(kml=functions.AsKML('name'))
119119

120120
# Ensuring the KML is as expected.
121-
ptown = City.objects.annotate(kml=functions.AsKML('point', precision=9)).get(name='Pueblo')
121+
qs = City.objects.annotate(kml=functions.AsKML('point', precision=9))
122+
ptown = qs.get(name='Pueblo')
122123
self.assertEqual('<Point><coordinates>-104.609252,38.255001</coordinates></Point>', ptown.kml)
124+
# Same result if the queryset is evaluated again.
125+
self.assertEqual(qs.get(name='Pueblo').kml, ptown.kml)
123126

124127
@skipUnlessDBFeature("has_AsSVG_function")
125128
def test_assvg(self):

0 commit comments

Comments
 (0)