summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_constraints.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-14 13:09:24 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-14 20:56:04 +0200
commitee0abac169c2dcc6818d583247903c2a8ef55f7c (patch)
tree4c9486072a021b465a9c10039e395fc6c3de2d61 /tests/postgres_tests/test_constraints.py
parentbbd55e58639c33b4c5adff5f41b78deffc915c11 (diff)
Refs #32096 -- Fixed ExclusionConstraint crash with JSONField key transforms in expressions.
Regression in 6789ded0a6ab797f0dcdfa6ad5d1cfa46e23abcd.
Diffstat (limited to 'tests/postgres_tests/test_constraints.py')
-rw-r--r--tests/postgres_tests/test_constraints.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py
index 89463650e8..8621d7a052 100644
--- a/tests/postgres_tests/test_constraints.py
+++ b/tests/postgres_tests/test_constraints.py
@@ -7,6 +7,7 @@ from django.db import (
from django.db.models import (
CheckConstraint, Deferrable, F, Func, Q, UniqueConstraint,
)
+from django.db.models.fields.json import KeyTextTransform
from django.db.models.functions import Left
from django.test import skipUnlessDBFeature
from django.utils import timezone
@@ -620,6 +621,22 @@ class ExclusionConstraintTests(PostgreSQLTestCase):
editor.add_constraint(Scene, constraint)
self.assertIn(constraint_name, self.get_constraints(Scene._meta.db_table))
+ def test_expressions_with_key_transform(self):
+ constraint_name = 'exclude_overlapping_reservations_smoking'
+ constraint = ExclusionConstraint(
+ name=constraint_name,
+ expressions=[
+ (F('datespan'), RangeOperators.OVERLAPS),
+ (KeyTextTransform('smoking', 'requirements'), RangeOperators.EQUAL),
+ ],
+ )
+ with connection.schema_editor() as editor:
+ editor.add_constraint(HotelReservation, constraint)
+ self.assertIn(
+ constraint_name,
+ self.get_constraints(HotelReservation._meta.db_table),
+ )
+
def test_range_adjacent_initially_deferred(self):
constraint_name = 'ints_adjacent_deferred'
self.assertNotIn(constraint_name, self.get_constraints(RangesModel._meta.db_table))