diff options
| author | Tilman Koschnick <til@subnetz.org> | 2021-01-28 17:50:54 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-01-29 11:26:51 +0100 |
| commit | 18cac6bbfb3cdc02d4891ad01d9f358cce96e86a (patch) | |
| tree | 9534b92ce594380607ebcc6265b1c60de2c65697 /tests/postgres_tests | |
| parent | f4d51e12aed80bc1c12a2848a51e8af4e627ab97 (diff) | |
[3.2.x] Fixed #32392 -- Fixed ExclusionConstraint crash with Cast() in expressions.
Backport of fdfbc66331292def201c9344e3cd29fbcbcd076a from master
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/test_constraints.py | 15 | ||||
| -rw-r--r-- | tests/postgres_tests/test_indexes.py | 2 |
2 files changed, 14 insertions, 3 deletions
diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py index 8621d7a052..1bf52d0cc0 100644 --- a/tests/postgres_tests/test_constraints.py +++ b/tests/postgres_tests/test_constraints.py @@ -5,10 +5,10 @@ from django.db import ( IntegrityError, NotSupportedError, connection, transaction, ) from django.db.models import ( - CheckConstraint, Deferrable, F, Func, Q, UniqueConstraint, + CheckConstraint, Deferrable, F, Func, IntegerField, Q, UniqueConstraint, ) from django.db.models.fields.json import KeyTextTransform -from django.db.models.functions import Left +from django.db.models.functions import Cast, Left from django.test import skipUnlessDBFeature from django.utils import timezone @@ -783,3 +783,14 @@ class ExclusionConstraintTests(PostgreSQLTestCase): with connection.schema_editor() as editor: editor.add_constraint(RangesModel, constraint) self.assertIn(constraint_name, self.get_constraints(RangesModel._meta.db_table)) + + def test_range_equal_cast(self): + constraint_name = 'exclusion_equal_room_cast' + self.assertNotIn(constraint_name, self.get_constraints(Room._meta.db_table)) + constraint = ExclusionConstraint( + name=constraint_name, + expressions=[(Cast('number', IntegerField()), RangeOperators.EQUAL)], + ) + with connection.schema_editor() as editor: + editor.add_constraint(Room, constraint) + self.assertIn(constraint_name, self.get_constraints(Room._meta.db_table)) diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py index 49646feb97..0f01c1406e 100644 --- a/tests/postgres_tests/test_indexes.py +++ b/tests/postgres_tests/test_indexes.py @@ -305,7 +305,7 @@ class SchemaTests(PostgreSQLTestCase): self.assertIn(index_name, constraints) self.assertIn(constraints[index_name]['type'], GinIndex.suffix) self.assertIs(sql.references_column(table, 'field'), True) - self.assertIn('::tsvector', str(sql)) + self.assertIn(' AS tsvector', str(sql)) with connection.schema_editor() as editor: editor.remove_index(TextFieldModel, index) self.assertNotIn(index_name, self.get_constraints(table)) |
