Skip to content

Commit

Permalink
Fixed #25629 -- Added checks of the number of arguments for GeoDjango…
Browse files Browse the repository at this point in the history
… DB functions.
  • Loading branch information
sir-sigurd committed Nov 2, 2015
1 parent 0a26121 commit d812988
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 15 additions & 9 deletions django/contrib/gis/db/models/functions.py
Expand Up @@ -125,6 +125,8 @@ def as_oracle(self, compiler, connection):


class Area(OracleToleranceMixin, GeoFunc):
arity = 1

def as_sql(self, compiler, connection):
if connection.ops.geography:
# Geography fields support area calculation, returns square meters.
Expand Down Expand Up @@ -204,11 +206,11 @@ def __init__(self, expression, num_seg=48, **extra):


class Centroid(OracleToleranceMixin, GeoFunc):
pass
arity = 1


class Difference(OracleToleranceMixin, GeoFuncWithGeoParam):
pass
arity = 2


class DistanceResultMixin(object):
Expand Down Expand Up @@ -267,11 +269,11 @@ def as_oracle(self, compiler, connection):


class Envelope(GeoFunc):
pass
arity = 1


class ForceRHR(GeoFunc):
pass
arity = 1


class GeoHash(GeoFunc):
Expand All @@ -285,7 +287,7 @@ def __init__(self, expression, precision=None, **extra):


class Intersection(OracleToleranceMixin, GeoFuncWithGeoParam):
pass
arity = 2


class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
Expand Down Expand Up @@ -329,14 +331,17 @@ def as_sqlite(self, compiler, connection):

class MemSize(GeoFunc):
output_field_class = IntegerField
arity = 1


class NumGeometries(GeoFunc):
output_field_class = IntegerField
arity = 1


class NumPoints(GeoFunc):
output_field_class = IntegerField
arity = 1

def as_sqlite(self, compiler, connection):
if self.source_expressions[self.geom_param_pos].output_field.geom_type != 'LINESTRING':
Expand All @@ -346,6 +351,7 @@ def as_sqlite(self, compiler, connection):

class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
output_field_class = FloatField
arity = 1

def as_postgresql(self, compiler, connection):
dim = min(f.dim for f in self.get_source_fields())
Expand All @@ -355,11 +361,11 @@ def as_postgresql(self, compiler, connection):


class PointOnSurface(OracleToleranceMixin, GeoFunc):
pass
arity = 1


class Reverse(GeoFunc):
pass
arity = 1


class Scale(SQLiteDecimalToFloatMixin, GeoFunc):
Expand Down Expand Up @@ -396,7 +402,7 @@ def __init__(self, expression, *args, **extra):


class SymDifference(OracleToleranceMixin, GeoFuncWithGeoParam):
pass
arity = 2


class Transform(GeoFunc):
Expand Down Expand Up @@ -432,4 +438,4 @@ def as_sqlite(self, compiler, connection):


class Union(OracleToleranceMixin, GeoFuncWithGeoParam):
pass
arity = 2
3 changes: 3 additions & 0 deletions tests/gis_tests/geoapp/test_functions.py
Expand Up @@ -160,6 +160,9 @@ def test_centroid(self):
for state in qs:
self.assertTrue(state.poly.centroid.equals_exact(state.centroid, tol))

with self.assertRaisesMessage(TypeError, "'Centroid' takes exactly 1 argument (2 given)"):
State.objects.annotate(centroid=functions.Centroid('poly', 'poly'))

@skipUnlessDBFeature("has_Difference_function")
def test_difference(self):
geom = Point(5, 23, srid=4326)
Expand Down

0 comments on commit d812988

Please sign in to comment.