Skip to content

Commit

Permalink
Fixed #32923 -- Refactored out Field._clean_bound_field().
Browse files Browse the repository at this point in the history
  • Loading branch information
Waheedsys authored Jan 23, 2024
1 parent bbfbf0a commit d9b91e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 8 additions & 0 deletions django/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def __deepcopy__(self, memo):
result.validators = self.validators[:]
return result

def _clean_bound_field(self, bf):
value = bf.initial if self.disabled else bf.data
return self.clean(value)


class CharField(Field):
def __init__(
Expand Down Expand Up @@ -694,6 +698,10 @@ def bound_data(self, _, initial):
def has_changed(self, initial, data):
return not self.disabled and data is not None

def _clean_bound_field(self, bf):
value = bf.initial if self.disabled else bf.data
return self.clean(value, bf.initial)


class ImageField(FileField):
default_validators = [validators.validate_image_file_extension]
Expand Down
9 changes: 2 additions & 7 deletions django/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import datetime

from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
from django.forms.fields import Field, FileField
from django.forms.fields import Field
from django.forms.utils import ErrorDict, ErrorList, RenderableFormMixin
from django.forms.widgets import Media, MediaDefiningClass
from django.utils.datastructures import MultiValueDict
Expand Down Expand Up @@ -329,13 +329,8 @@ def full_clean(self):
def _clean_fields(self):
for name, bf in self._bound_items():
field = bf.field
value = bf.initial if field.disabled else bf.data
try:
if isinstance(field, FileField):
value = field.clean(value, bf.initial)
else:
value = field.clean(value)
self.cleaned_data[name] = value
self.cleaned_data[name] = field._clean_bound_field(bf)
if hasattr(self, "clean_%s" % name):
value = getattr(self, "clean_%s" % name)()
self.cleaned_data[name] = value
Expand Down

0 comments on commit d9b91e3

Please sign in to comment.