mirror of
https://github.com/django/django.git
synced 2025-07-30 08:35:23 +00:00
Fixed #35275 -- Fixed Meta.constraints validation crash on UniqueConstraint with OpClass().
This also introduces Expression.constraint_validation_compatible that allows specifying that expression should be ignored during a constraint validation.
This commit is contained in:
parent
ceaf1e2848
commit
f030236a86
8 changed files with 61 additions and 11 deletions
|
@ -266,6 +266,19 @@ class SchemaTests(PostgreSQLTestCase):
|
|||
self.assertNotIn(constraint.name, self.get_constraints(Scene._meta.db_table))
|
||||
Scene.objects.create(scene="ScEnE 10", setting="Sir Bedemir's Castle")
|
||||
|
||||
def test_opclass_func_validate_constraints(self):
|
||||
constraint_name = "test_opclass_func_validate_constraints"
|
||||
constraint = UniqueConstraint(
|
||||
OpClass(Lower("scene"), name="text_pattern_ops"),
|
||||
name="test_opclass_func_validate_constraints",
|
||||
)
|
||||
Scene.objects.create(scene="First scene")
|
||||
# Non-unique scene.
|
||||
msg = f"Constraint “{constraint_name}” is violated."
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
constraint.validate(Scene, Scene(scene="first Scene"))
|
||||
constraint.validate(Scene, Scene(scene="second Scene"))
|
||||
|
||||
|
||||
class ExclusionConstraintTests(PostgreSQLTestCase):
|
||||
def get_constraints(self, table):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue