mirror of
https://github.com/django/django.git
synced 2025-10-07 17:20:48 +00:00
[4.1.x] Fixed #33902 -- Fixed Meta.constraints validation crash with F() expressions.
Thanks Adam Zahradník for the report. Bug in667105877e
. Backport of63884829ac
from main
This commit is contained in:
parent
8ea203d112
commit
6b0193146d
4 changed files with 27 additions and 6 deletions
|
@ -685,6 +685,20 @@ class UniqueConstraintTests(TestCase):
|
|||
exclude={"color"},
|
||||
)
|
||||
|
||||
def test_validate_expression_str(self):
|
||||
constraint = models.UniqueConstraint("name", name="name_uniq")
|
||||
msg = "Constraint “name_uniq” is violated."
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
constraint.validate(
|
||||
UniqueConstraintProduct,
|
||||
UniqueConstraintProduct(name=self.p1.name),
|
||||
)
|
||||
constraint.validate(
|
||||
UniqueConstraintProduct,
|
||||
UniqueConstraintProduct(name=self.p1.name),
|
||||
exclude={"name"},
|
||||
)
|
||||
|
||||
def test_name(self):
|
||||
constraints = get_constraints(UniqueConstraintProduct._meta.db_table)
|
||||
expected_name = "name_color_uniq"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue