diff options
| author | David Sanders <shang.xiao.sanders@gmail.com> | 2024-08-05 08:22:29 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-08-05 17:36:15 +0200 |
| commit | aed4ffe1897c51c0dfd8689c0834ca4ca0a8a03e (patch) | |
| tree | 409778e06c17bbc9f828db340b431c030e5e400b /tests/validation | |
| parent | 78654a29b851751f347d51dbfe5ba8a996c012ba (diff) | |
[5.1.x] Fixed #35638 -- Updated validate_constraints to consider db_default.
Backport of 509763c79952cde02d9f5b584af4278bdbed77b2 from main.
Diffstat (limited to 'tests/validation')
| -rw-r--r-- | tests/validation/models.py | 2 | ||||
| -rw-r--r-- | tests/validation/test_unique.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/tests/validation/models.py b/tests/validation/models.py index f6b1e0cd62..beec524758 100644 --- a/tests/validation/models.py +++ b/tests/validation/models.py @@ -48,7 +48,7 @@ class ModelToValidate(models.Model): class UniqueFieldsModel(models.Model): unique_charfield = models.CharField(max_length=100, unique=True) - unique_integerfield = models.IntegerField(unique=True) + unique_integerfield = models.IntegerField(unique=True, db_default=42) non_unique_field = models.IntegerField() diff --git a/tests/validation/test_unique.py b/tests/validation/test_unique.py index 4a8b3894f0..36ee6e9da0 100644 --- a/tests/validation/test_unique.py +++ b/tests/validation/test_unique.py @@ -146,6 +146,20 @@ class PerformUniqueChecksTest(TestCase): mtv = ModelToValidate(number=10, name="Some Name") mtv.full_clean() + def test_unique_db_default(self): + UniqueFieldsModel.objects.create(unique_charfield="foo", non_unique_field=42) + um = UniqueFieldsModel(unique_charfield="bar", non_unique_field=42) + with self.assertRaises(ValidationError) as cm: + um.full_clean() + self.assertEqual( + cm.exception.message_dict, + { + "unique_integerfield": [ + "Unique fields model with this Unique integerfield already exists." + ] + }, + ) + def test_unique_for_date(self): Post.objects.create( title="Django 1.0 is released", |
