Skip to content

Commit 306b961

Browse files
sir-sigurdtimgraham
authored andcommitted
Fixed #28383 -- Made NumPoints GIS function return None for non-LINESTRING geometries on MySQL.
1 parent 719b370 commit 306b961

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,6 @@ class NumPoints(GeoFunc):
419419
output_field_class = IntegerField
420420
arity = 1
421421

422-
def as_sql(self, compiler, connection):
423-
if self.source_expressions[self.geom_param_pos[0]].output_field.geom_type != 'LINESTRING':
424-
if not connection.features.supports_num_points_poly:
425-
raise TypeError('NumPoints can only operate on LineString content on this database.')
426-
return super().as_sql(compiler, connection)
427-
428422

429423
class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
430424
arity = 1

tests/gis_tests/geoapp/test_functions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,8 @@ def test_num_points(self):
336336
self.assertEqual(qs.first().num_points, 2)
337337
mpoly_qs = Country.objects.annotate(num_points=functions.NumPoints('mpoly'))
338338
if not connection.features.supports_num_points_poly:
339-
msg = 'NumPoints can only operate on LineString content on this database.'
340-
with self.assertRaisesMessage(TypeError, msg):
341-
list(mpoly_qs)
339+
for c in mpoly_qs:
340+
self.assertIsNone(c.num_points)
342341
return
343342

344343
for c in mpoly_qs:

0 commit comments

Comments
 (0)