mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #36198 -- Implemented unresolved transform expression replacement.
This allows the proper resolving of F("field__transform") when
performing constraint validation.
Thanks Tom Hall for the report and Sarah for the test.
This commit is contained in:
committed by
Mariusz Felisiak
parent
ff3aaf036f
commit
fc30355107
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from unittest import mock
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
@@ -1030,6 +1031,23 @@ class UniqueConstraintTests(TestCase):
|
||||
exclude={"name"},
|
||||
)
|
||||
|
||||
def test_validate_field_transform(self):
|
||||
updated_date = datetime(2005, 7, 26)
|
||||
UniqueConstraintProduct.objects.create(name="p1", updated=updated_date)
|
||||
constraint = models.UniqueConstraint(
|
||||
models.F("updated__date"), name="date_created_unique"
|
||||
)
|
||||
msg = "Constraint “date_created_unique” is violated."
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
constraint.validate(
|
||||
UniqueConstraintProduct,
|
||||
UniqueConstraintProduct(updated=updated_date),
|
||||
)
|
||||
constraint.validate(
|
||||
UniqueConstraintProduct,
|
||||
UniqueConstraintProduct(updated=updated_date + timedelta(days=1)),
|
||||
)
|
||||
|
||||
def test_validate_ordered_expression(self):
|
||||
constraint = models.UniqueConstraint(
|
||||
Lower("name").desc(), name="name_lower_uniq_desc"
|
||||
|
||||
Reference in New Issue
Block a user