diff options
author | Claude Paroz <claude@2xlibre.net> | 2021-11-27 11:30:58 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-11-30 20:06:29 +0100 |
commit | 64c3f049ea3bcb1c82f35ae09f1dd5349a826a5c (patch) | |
tree | f3e109d0bea16be80020fa9da671c9ac3f8626b1 /tests/gis_tests | |
parent | ae4077e13ea2e4c460c3f21b9aab93a696590851 (diff) | |
download | django-64c3f049ea3bcb1c82f35ae09f1dd5349a826a5c.tar.gz |
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 <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/gis_tests')
-rw-r--r-- | tests/gis_tests/gis_migrations/test_operations.py | 18 |
1 files changed, 18 insertions, 0 deletions
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): |