diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 22a38050d..af7ab0231 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -133,7 +133,7 @@ def get_field_kwargs(field_name, model_field): if isinstance(model_field, models.DecimalField) and DecimalValidator: validator_kwarg = [ validator for validator in validator_kwarg - if DecimalValidator and not isinstance(validator, DecimalValidator) + if not isinstance(validator, DecimalValidator) ] # Ensure that max_length is passed explicitly as a keyword arg, diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index 2976b1984..af8ce66dd 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -22,7 +22,7 @@ from django.utils import six from rest_framework import serializers from rest_framework.compat import DurationField as ModelDurationField -from rest_framework.compat import DecimalValidator, unicode_repr +from rest_framework.compat import unicode_repr def dedent(blocktext): @@ -872,25 +872,9 @@ class DecimalFieldModel(models.Model): class TestDecimalFieldMappings(TestCase): - @pytest.mark.skipif(DecimalValidator is not None, - reason='DecimalValidator is available in Django 1.9+') - def test_decimal_field_has_no_decimal_validator(self): - """ - Test that a DecimalField has no validators before Django 1.9. - """ - class TestSerializer(serializers.ModelSerializer): - class Meta: - model = DecimalFieldModel - - serializer = TestSerializer() - - assert len(serializer.fields['decimal_field'].validators) == 2 - - @pytest.mark.skipif(DecimalValidator is None, - reason='DecimalValidator is available in Django 1.9+') def test_decimal_field_has_decimal_validator(self): """ - Test that a DecimalField has DecimalValidator in Django 1.9+. + Test that a `DecimalField` has no `DecimalValidator`. """ class TestSerializer(serializers.ModelSerializer): class Meta: