mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[5.0.x] Fixed #35223 -- Made Model.full_clean() ignore fields with db_default when validating empty values.
Thanks Brian Ibbotson for the report. Regression in7414704e88. Backport of1570ef02f3from main.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f931cbec21
commit
5f07460a67
@@ -30,7 +30,7 @@ from django.db.models import NOT_PROVIDED, ExpressionWrapper, IntegerField, Max,
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
from django.db.models.constraints import CheckConstraint, UniqueConstraint
|
||||
from django.db.models.deletion import CASCADE, Collector
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models.expressions import DatabaseDefault, RawSQL
|
||||
from django.db.models.fields.related import (
|
||||
ForeignObjectRel,
|
||||
OneToOneField,
|
||||
@@ -1568,6 +1568,9 @@ class Model(AltersData, metaclass=ModelBase):
|
||||
raw_value = getattr(self, f.attname)
|
||||
if f.blank and raw_value in f.empty_values:
|
||||
continue
|
||||
# Skip validation for empty fields when db_default is used.
|
||||
if isinstance(raw_value, DatabaseDefault):
|
||||
continue
|
||||
try:
|
||||
setattr(self, f.attname, f.clean(raw_value, self))
|
||||
except ValidationError as e:
|
||||
|
||||
Reference in New Issue
Block a user