mirror of
https://github.com/django/django.git
synced 2025-10-27 23:56:08 +00:00
Fixed #35223 -- Made Model.full_clean() ignore fields with db_default when validating empty values.
Thanks Brian Ibbotson for the report.
Regression in 7414704e88.
This commit is contained in:
committed by
Mariusz Felisiak
parent
1669e54965
commit
1570ef02f3
@@ -2,6 +2,7 @@ from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from math import pi
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import connection
|
||||
from django.db.models import Case, F, FloatField, Value, When
|
||||
from django.db.models.expressions import (
|
||||
@@ -169,6 +170,23 @@ class DefaultTests(TestCase):
|
||||
years = DBDefaultsFunction.objects.values_list("year", flat=True)
|
||||
self.assertCountEqual(years, [2000, datetime.now().year])
|
||||
|
||||
def test_full_clean(self):
|
||||
obj = DBArticle()
|
||||
obj.full_clean()
|
||||
obj.save()
|
||||
obj.refresh_from_db()
|
||||
self.assertEqual(obj.headline, "Default headline")
|
||||
|
||||
obj = DBArticle(headline="Other title")
|
||||
obj.full_clean()
|
||||
obj.save()
|
||||
obj.refresh_from_db()
|
||||
self.assertEqual(obj.headline, "Other title")
|
||||
|
||||
obj = DBArticle(headline="")
|
||||
with self.assertRaises(ValidationError):
|
||||
obj.full_clean()
|
||||
|
||||
|
||||
class AllowedDefaultTests(SimpleTestCase):
|
||||
def test_allowed(self):
|
||||
|
||||
Reference in New Issue
Block a user