summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-07-11 18:21:11 +0600
committerTim Graham <timograham@gmail.com>2017-07-11 08:21:11 -0400
commit306b961a4dc1fd308c6f298b406fb41906ebaf2d (patch)
tree317d98ae863c85f2509434856a132da2a848cb06
parent719b370b34ee0b9b4c115da1ce73d1748cd48dd7 (diff)
Fixed #28383 -- Made NumPoints GIS function return None for non-LINESTRING geometries on MySQL.
-rw-r--r--django/contrib/gis/db/models/functions.py6
-rw-r--r--tests/gis_tests/geoapp/test_functions.py5
2 files changed, 2 insertions, 9 deletions
diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py
index 85f704c1ef..907fe8e456 100644
--- a/django/contrib/gis/db/models/functions.py
+++ b/django/contrib/gis/db/models/functions.py
@@ -419,12 +419,6 @@ class NumPoints(GeoFunc):
output_field_class = IntegerField
arity = 1
- def as_sql(self, compiler, connection):
- if self.source_expressions[self.geom_param_pos[0]].output_field.geom_type != 'LINESTRING':
- if not connection.features.supports_num_points_poly:
- raise TypeError('NumPoints can only operate on LineString content on this database.')
- return super().as_sql(compiler, connection)
-
class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
arity = 1
diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py
index 9d17a625ee..bbf29b0aff 100644
--- a/tests/gis_tests/geoapp/test_functions.py
+++ b/tests/gis_tests/geoapp/test_functions.py
@@ -336,9 +336,8 @@ class GISFunctionsTests(TestCase):
self.assertEqual(qs.first().num_points, 2)
mpoly_qs = Country.objects.annotate(num_points=functions.NumPoints('mpoly'))
if not connection.features.supports_num_points_poly:
- msg = 'NumPoints can only operate on LineString content on this database.'
- with self.assertRaisesMessage(TypeError, msg):
- list(mpoly_qs)
+ for c in mpoly_qs:
+ self.assertIsNone(c.num_points)
return
for c in mpoly_qs: