From bf6d07730c41ae23836d8dae98626fe8614307e2 Mon Sep 17 00:00:00 2001 From: Maxim Petrov Date: Wed, 19 Aug 2020 05:22:12 +0300 Subject: Fixed #31902 -- Fixed crash of ExclusionConstraint on expressions with params. --- tests/postgres_tests/test_constraints.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/postgres_tests') diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py index 7d79e65239..89463650e8 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.functions import Left from django.test import skipUnlessDBFeature from django.utils import timezone @@ -608,6 +609,17 @@ class ExclusionConstraintTests(PostgreSQLTestCase): editor.remove_constraint(RangesModel, constraint) self.assertNotIn(constraint_name, self.get_constraints(RangesModel._meta.db_table)) + def test_expressions_with_params(self): + constraint_name = 'scene_left_equal' + self.assertNotIn(constraint_name, self.get_constraints(Scene._meta.db_table)) + constraint = ExclusionConstraint( + name=constraint_name, + expressions=[(Left('scene', 4), RangeOperators.EQUAL)], + ) + with connection.schema_editor() as editor: + editor.add_constraint(Scene, constraint) + self.assertIn(constraint_name, self.get_constraints(Scene._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)) -- cgit v1.3