From 64c3f049ea3bcb1c82f35ae09f1dd5349a826a5c Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 27 Nov 2021 11:30:58 +0100 Subject: Fixed #33047 -- Fixed CheckConstraint crash with GIS lookups on PostGIS and MySQL GIS backends. Thanks Daniel Swain for the report and Arsalan Ghassemi for the initial patch. Co-authored-by: Mariusz Felisiak --- tests/gis_tests/gis_migrations/test_operations.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/gis_tests/gis_migrations/test_operations.py b/tests/gis_tests/gis_migrations/test_operations.py index 6c7adcf359..b7823dd983 100644 --- a/tests/gis_tests/gis_migrations/test_operations.py +++ b/tests/gis_tests/gis_migrations/test_operations.py @@ -235,6 +235,24 @@ class OperationTests(OperationTestCase): ) self.assertFalse(Neighborhood.objects.first().geom.hasz) + @skipUnlessDBFeature('supports_column_check_constraints', 'can_introspect_check_constraints') + def test_add_check_constraint(self): + Neighborhood = self.current_state.apps.get_model('gis', 'Neighborhood') + poly = Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))) + constraint = models.CheckConstraint( + check=models.Q(geom=poly), + name='geom_within_constraint', + ) + Neighborhood._meta.constraints = [constraint] + with connection.schema_editor() as editor: + editor.add_constraint(Neighborhood, constraint) + with connection.cursor() as cursor: + constraints = connection.introspection.get_constraints( + cursor, + Neighborhood._meta.db_table, + ) + self.assertIn('geom_within_constraint', constraints) + @skipIfDBFeature('supports_raster') class NoRasterSupportTests(OperationTestCase): -- cgit v1.3