From c9e85443211715993d7b27af2bf772380e26f6de Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 11 Nov 2020 01:39:15 -0500 Subject: [PATCH] Added SpatialFeatures.unsupported_geojson_options. --- django/contrib/gis/db/backends/base/features.py | 3 +++ django/contrib/gis/db/backends/mysql/features.py | 1 + django/contrib/gis/db/backends/oracle/features.py | 1 + tests/gis_tests/geoapp/test_functions.py | 7 +++---- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/django/contrib/gis/db/backends/base/features.py b/django/contrib/gis/db/backends/base/features.py index e714440e58..a88ad03684 100644 --- a/django/contrib/gis/db/backends/base/features.py +++ b/django/contrib/gis/db/backends/base/features.py @@ -51,6 +51,9 @@ class BaseSpatialFeatures: # Can SchemaEditor alter geometry fields? can_alter_geometry_field = True + # Set of options that AsGeoJSON() doesn't support. + unsupported_geojson_options = {} + @property def supports_bbcontains_lookup(self): return 'bbcontains' in self.connection.ops.gis_operators diff --git a/django/contrib/gis/db/backends/mysql/features.py b/django/contrib/gis/db/backends/mysql/features.py index 424df28d94..63e2fa1dd3 100644 --- a/django/contrib/gis/db/backends/mysql/features.py +++ b/django/contrib/gis/db/backends/mysql/features.py @@ -14,6 +14,7 @@ class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures): supports_transform = False supports_null_geometries = False supports_num_points_poly = False + unsupported_geojson_options = {'crs'} @cached_property def supports_empty_geometry_collection(self): diff --git a/django/contrib/gis/db/backends/oracle/features.py b/django/contrib/gis/db/backends/oracle/features.py index f2ed4d3076..80c71e0dcb 100644 --- a/django/contrib/gis/db/backends/oracle/features.py +++ b/django/contrib/gis/db/backends/oracle/features.py @@ -10,3 +10,4 @@ class DatabaseFeatures(BaseSpatialFeatures, OracleDatabaseFeatures): supports_geometry_field_unique_index = False supports_perimeter_geodetic = True supports_dwithin_distance_expr = False + unsupported_geojson_options = {'bbox', 'crs', 'precision'} diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index c2e06db4c5..b518f9cb53 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -44,14 +44,13 @@ class GISFunctionsTests(FuncTestMixin, TestCase): '{"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4326"}},' '"bbox":[-87.65018,41.85039,-87.65018,41.85039],"coordinates":[-87.65018,41.85039]}' ) - # MySQL and Oracle ignore the crs option. - if mysql or oracle: + if 'crs' in connection.features.unsupported_geojson_options: del houston_json['crs'] del chicago_json['crs'] - # Oracle ignores also the bbox and precision options. - if oracle: + if 'bbox' in connection.features.unsupported_geojson_options: del chicago_json['bbox'] del victoria_json['bbox'] + if 'precision' in connection.features.unsupported_geojson_options: chicago_json['coordinates'] = [-87.650175, 41.850385] # Precision argument should only be an integer