diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py index 55324a8eaa6e4..c222f08b1ba60 100644 --- a/django/contrib/gis/db/models/functions.py +++ b/django/contrib/gis/db/models/functions.py @@ -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. @@ -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): @@ -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): @@ -285,7 +287,7 @@ def __init__(self, expression, precision=None, **extra): class Intersection(OracleToleranceMixin, GeoFuncWithGeoParam): - pass + arity = 2 class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc): @@ -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': @@ -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()) @@ -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): @@ -396,7 +402,7 @@ def __init__(self, expression, *args, **extra): class SymDifference(OracleToleranceMixin, GeoFuncWithGeoParam): - pass + arity = 2 class Transform(GeoFunc): @@ -432,4 +438,4 @@ def as_sqlite(self, compiler, connection): class Union(OracleToleranceMixin, GeoFuncWithGeoParam): - pass + arity = 2 diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index ff99cc485511f..d7788104805e3 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -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)