Skip to content

Commit 87605e1

Browse files
committed
Don't filter out the DecimalValidator if it is not supported
Previously, all validators set on a DecimalField in Django would be stripped when converted to a Django REST framework field. This was because any validator that was an instance of `DecimalValidator` would be removed, and when `DecimalValidator` wasn't supported (so it was `None`), all validators would be removed. This fixes the issue by only removing the `DecimalValidator` instances if the `DecimalValidator` is supported.
1 parent 9bab640 commit 87605e1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rest_framework/utils/field_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_field_kwargs(field_name, model_field):
130130

131131
# Our decimal validation is handled in the field code, not validator code.
132132
# (In Django 1.9+ this differs from previous style)
133-
if isinstance(model_field, models.DecimalField):
133+
if isinstance(model_field, models.DecimalField) and DecimalValidator:
134134
validator_kwarg = [
135135
validator for validator in validator_kwarg
136136
if DecimalValidator and not isinstance(validator, DecimalValidator)

0 commit comments

Comments
 (0)