diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-14 13:09:24 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-14 22:10:09 +0200 |
| commit | 536213278c77884e9f985c18a8f9e1158f0d680a (patch) | |
| tree | fa7991fd0970addfad18c2df3008caec05d5b174 /tests/postgres_tests | |
| parent | ae6b24093c7ccc730850d11bbe93e1481ebd2912 (diff) | |
[3.1.x] Refs #32096 -- Fixed ExclusionConstraint crash with JSONField key transforms in expressions.
Regression in 6789ded0a6ab797f0dcdfa6ad5d1cfa46e23abcd.
Backport of ee0abac169c2dcc6818d583247903c2a8ef55f7c from master.
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/migrations/0002_create_test_models.py | 1 | ||||
| -rw-r--r-- | tests/postgres_tests/models.py | 1 | ||||
| -rw-r--r-- | tests/postgres_tests/test_constraints.py | 17 |
3 files changed, 19 insertions, 0 deletions
diff --git a/tests/postgres_tests/migrations/0002_create_test_models.py b/tests/postgres_tests/migrations/0002_create_test_models.py index e334057d22..cd8b20ae01 100644 --- a/tests/postgres_tests/migrations/0002_create_test_models.py +++ b/tests/postgres_tests/migrations/0002_create_test_models.py @@ -303,6 +303,7 @@ class Migration(migrations.Migration): ('start', models.DateTimeField()), ('end', models.DateTimeField()), ('cancelled', models.BooleanField(default=False)), + ('requirements', models.JSONField(blank=True, null=True)), ], options={ 'required_db_vendor': 'postgresql', diff --git a/tests/postgres_tests/models.py b/tests/postgres_tests/models.py index a5bfc72fe7..56c81064f3 100644 --- a/tests/postgres_tests/models.py +++ b/tests/postgres_tests/models.py @@ -191,3 +191,4 @@ class HotelReservation(PostgreSQLModel): start = models.DateTimeField() end = models.DateTimeField() cancelled = models.BooleanField(default=False) + requirements = models.JSONField(blank=True, null=True) diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py index 4c2e04705d..35bde7ba06 100644 --- a/tests/postgres_tests/test_constraints.py +++ b/tests/postgres_tests/test_constraints.py @@ -3,6 +3,7 @@ from unittest import mock from django.db import IntegrityError, connection, transaction from django.db.models import CheckConstraint, Deferrable, F, Func, Q +from django.db.models.fields.json import KeyTextTransform from django.utils import timezone from . import PostgreSQLTestCase @@ -397,6 +398,22 @@ class ExclusionConstraintTests(PostgreSQLTestCase): editor.remove_constraint(RangesModel, constraint) self.assertNotIn(constraint_name, self.get_constraints(RangesModel._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)) |
