mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
Fixed #34291 -- Fixed Meta.constraints validation crash on UniqueConstraint with ordered expressions.
Thanks Dan F for the report.
Bug in 667105877e.
This commit is contained in:
parent
882f99031e
commit
2b1242abb3
3 changed files with 32 additions and 6 deletions
|
|
@ -672,6 +672,29 @@ class UniqueConstraintTests(TestCase):
|
|||
exclude={"name"},
|
||||
)
|
||||
|
||||
def test_validate_ordered_expression(self):
|
||||
constraint = models.UniqueConstraint(
|
||||
Lower("name").desc(), name="name_lower_uniq_desc"
|
||||
)
|
||||
msg = "Constraint “name_lower_uniq_desc” is violated."
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
constraint.validate(
|
||||
UniqueConstraintProduct,
|
||||
UniqueConstraintProduct(name=self.p1.name.upper()),
|
||||
)
|
||||
constraint.validate(
|
||||
UniqueConstraintProduct,
|
||||
UniqueConstraintProduct(name="another-name"),
|
||||
)
|
||||
# Existing instances have their existing row excluded.
|
||||
constraint.validate(UniqueConstraintProduct, self.p1)
|
||||
# Unique field is excluded.
|
||||
constraint.validate(
|
||||
UniqueConstraintProduct,
|
||||
UniqueConstraintProduct(name=self.p1.name.upper()),
|
||||
exclude={"name"},
|
||||
)
|
||||
|
||||
def test_validate_expression_condition(self):
|
||||
constraint = models.UniqueConstraint(
|
||||
Lower("name"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue