From 0eee5c1b9c2e306aa2c2807daf146ee88676bc97 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 19 Oct 2020 06:41:52 -0400 Subject: [PATCH] Added DatabaseFeatures.can_alter_geometry_field. --- django/contrib/gis/db/backends/base/features.py | 3 +++ django/contrib/gis/db/backends/spatialite/features.py | 1 + tests/gis_tests/gis_migrations/test_operations.py | 7 +++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/django/contrib/gis/db/backends/base/features.py b/django/contrib/gis/db/backends/base/features.py index 019b118765..ff16701795 100644 --- a/django/contrib/gis/db/backends/base/features.py +++ b/django/contrib/gis/db/backends/base/features.py @@ -46,6 +46,9 @@ class BaseSpatialFeatures: # Does the database support a unique index on geometry fields? supports_geometry_field_unique_index = True + # Can SchemaEditor alter geometry fields? + can_alter_geometry_field = True + @property def supports_bbcontains_lookup(self): return 'bbcontains' in self.connection.ops.gis_operators diff --git a/django/contrib/gis/db/backends/spatialite/features.py b/django/contrib/gis/db/backends/spatialite/features.py index d29e7876ae..6e5bd95179 100644 --- a/django/contrib/gis/db/backends/spatialite/features.py +++ b/django/contrib/gis/db/backends/spatialite/features.py @@ -6,6 +6,7 @@ from django.utils.functional import cached_property class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures): + can_alter_geometry_field = False # Not implemented supports_3d_storage = True @cached_property diff --git a/tests/gis_tests/gis_migrations/test_operations.py b/tests/gis_tests/gis_migrations/test_operations.py index 22bda55302..020d10b865 100644 --- a/tests/gis_tests/gis_migrations/test_operations.py +++ b/tests/gis_tests/gis_migrations/test_operations.py @@ -1,4 +1,4 @@ -from unittest import skipIf, skipUnless +from unittest import skipUnless from django.contrib.gis.db.models import fields from django.contrib.gis.geos import MultiPolygon, Polygon @@ -10,7 +10,7 @@ from django.test import ( TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature, ) -from ..utils import mysql, oracle, spatialite +from ..utils import mysql, oracle try: GeometryColumns = connection.ops.geometry_columns() @@ -190,8 +190,7 @@ class OperationTests(OperationTestCase): if connection.features.supports_raster: self.assertSpatialIndexExists('gis_neighborhood', 'rast', raster=True) - @skipUnlessDBFeature("supports_3d_storage") - @skipIf(spatialite, "Django currently doesn't support altering Spatialite geometry fields") + @skipUnlessDBFeature('can_alter_geometry_field', 'supports_3d_storage') def test_alter_geom_field_dim(self): Neighborhood = self.current_state.apps.get_model('gis', 'Neighborhood') p1 = Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)))