diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2015-10-30 19:47:35 +0500 |
|---|---|---|
| committer | Claude Paroz <claude@localhost.localdomain> | 2015-11-03 08:20:08 +0100 |
| commit | a449b7ef99efdbb5edc8b4aacc89eb6020145dd3 (patch) | |
| tree | beca806df8d9f62178bb2e8db25245c87013111c | |
| parent | 1b598b4b423f7f3b63d523a4cc1e42e5364dd415 (diff) | |
Fixed #25629 -- Added checks of the number of arguments for GeoDjango DB functions.
| -rw-r--r-- | django/contrib/gis/db/models/functions.py | 24 | ||||
| -rw-r--r-- | tests/gis_tests/geoapp/test_functions.py | 3 |
2 files changed, 18 insertions, 9 deletions
diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py index 55324a8eaa..c222f08b1b 100644 --- a/django/contrib/gis/db/models/functions.py +++ b/django/contrib/gis/db/models/functions.py @@ -125,6 +125,8 @@ class OracleToleranceMixin(object): 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 @@ class BoundingCircle(GeoFunc): class Centroid(OracleToleranceMixin, GeoFunc): - pass + arity = 1 class Difference(OracleToleranceMixin, GeoFuncWithGeoParam): - pass + arity = 2 class DistanceResultMixin(object): @@ -267,11 +269,11 @@ class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFuncWithGeoParam): class Envelope(GeoFunc): - pass + arity = 1 class ForceRHR(GeoFunc): - pass + arity = 1 class GeoHash(GeoFunc): @@ -285,7 +287,7 @@ class GeoHash(GeoFunc): class Intersection(OracleToleranceMixin, GeoFuncWithGeoParam): - pass + arity = 2 class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc): @@ -329,14 +331,17 @@ class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc): 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 @@ class NumPoints(GeoFunc): 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 @@ class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc): class PointOnSurface(OracleToleranceMixin, GeoFunc): - pass + arity = 1 class Reverse(GeoFunc): - pass + arity = 1 class Scale(SQLiteDecimalToFloatMixin, GeoFunc): @@ -396,7 +402,7 @@ class SnapToGrid(SQLiteDecimalToFloatMixin, GeoFunc): class SymDifference(OracleToleranceMixin, GeoFuncWithGeoParam): - pass + arity = 2 class Transform(GeoFunc): @@ -432,4 +438,4 @@ class Translate(Scale): 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 ff99cc4855..d778810480 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -160,6 +160,9 @@ class GISFunctionsTests(TestCase): 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) |
