diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2017-03-23 23:27:13 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-03-23 19:09:04 -0400 |
| commit | e9149d3eb0ed0ddc8b27b1990eb2b7293c1231cd (patch) | |
| tree | 36bdda886a26c319d6eadc0cc8f168d3d430f646 | |
| parent | 7e09fa7f519daf2f9c26587c3da5dc044d84b032 (diff) | |
Fixed #27603 -- Fixed AsKML when queryset is evaluated more than once.
| -rw-r--r-- | django/contrib/gis/db/models/functions.py | 5 | ||||
| -rw-r--r-- | tests/gis_tests/geoapp/test_functions.py | 5 |
2 files changed, 7 insertions, 3 deletions
diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py index 01b2c93446..b688299cb5 100644 --- a/django/contrib/gis/db/models/functions.py +++ b/django/contrib/gis/db/models/functions.py @@ -195,8 +195,9 @@ class AsGML(GeoFunc): class AsKML(AsGML): def as_sqlite(self, compiler, connection): # No version parameter - self.source_expressions.pop(0) - return super().as_sql(compiler, connection) + clone = self.copy() + clone.set_source_expressions(self.get_source_expressions()[1:]) + return clone.as_sql(compiler, connection) class AsSVG(GeoFunc): diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index ac429dfda9..9896aff5c3 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -118,8 +118,11 @@ class GISFunctionsTests(TestCase): City.objects.annotate(kml=functions.AsKML('name')) # 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) + # Same result if the queryset is evaluated again. + self.assertEqual(qs.get(name='Pueblo').kml, ptown.kml) @skipUnlessDBFeature("has_AsSVG_function") def test_assvg(self): |
