Skip to content

Commit

Permalink
Fixed #31142 -- Fixed MakeValid.output_field when geometry type is ch…
Browse files Browse the repository at this point in the history
…anged.

Regression in 2ef4b47.
  • Loading branch information
sir-sigurd authored and felixxm committed Jan 20, 2020
1 parent 7d8df4a commit a920c0b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django/contrib/gis/db/models/functions.py
Expand Up @@ -376,7 +376,7 @@ class LineLocatePoint(GeoFunc):
geom_param_pos = (0, 1)


class MakeValid(GeoFunc):
class MakeValid(GeomOutputGeoFunc):
pass


Expand Down
32 changes: 30 additions & 2 deletions tests/gis_tests/geoapp/test_functions.py
Expand Up @@ -3,13 +3,13 @@
import re
from decimal import Decimal

from django.contrib.gis.db.models import functions
from django.contrib.gis.db.models import GeometryField, PolygonField, functions
from django.contrib.gis.geos import (
GEOSGeometry, LineString, Point, Polygon, fromstr,
)
from django.contrib.gis.measure import Area
from django.db import NotSupportedError, connection
from django.db.models import Sum
from django.db.models import Sum, Value
from django.test import TestCase, skipUnlessDBFeature

from ..utils import FuncTestMixin, mariadb, mysql, oracle, postgis, spatialite
Expand Down Expand Up @@ -348,6 +348,34 @@ def test_make_valid(self):
self.assertIs(invalid.repaired.valid, True)
self.assertEqual(invalid.repaired, fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', srid=invalid.poly.srid))

@skipUnlessDBFeature('has_MakeValid_function')
def test_make_valid_multipolygon(self):
invalid_geom = fromstr(
'POLYGON((0 0, 0 1 , 1 1 , 1 0, 0 0), '
'(10 0, 10 1, 11 1, 11 0, 10 0))'
)
State.objects.create(name='invalid', poly=invalid_geom)
invalid = State.objects.filter(name='invalid').annotate(
repaired=functions.MakeValid('poly'),
).get()
self.assertIs(invalid.repaired.valid, True)
self.assertEqual(invalid.repaired, fromstr(
'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), '
'((10 0, 10 1, 11 1, 11 0, 10 0)))',
srid=invalid.poly.srid,
))
self.assertEqual(len(invalid.repaired), 2)

@skipUnlessDBFeature('has_MakeValid_function')
def test_make_valid_output_field(self):
# output_field is GeometryField instance because different geometry
# types can be returned.
output_field = functions.MakeValid(
Value(Polygon(), PolygonField(srid=42)),
).output_field
self.assertIs(output_field.__class__, GeometryField)
self.assertEqual(output_field.srid, 42)

@skipUnlessDBFeature("has_MemSize_function")
def test_memsize(self):
ptown = City.objects.annotate(size=functions.MemSize('point')).get(name='Pueblo')
Expand Down

0 comments on commit a920c0b

Please sign in to comment.