﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26786	Redundant range validators on integer fields	Eduard Stepanov	Eduard Stepanov	"For example, I have the following model:

{{{
#!python
from django.db import models
from django.core.validators import MaxValueValidator

class AModel(models.Model):
    number = models.IntegerField(""Test"", validators=[MaxValueValidator(100)])
}}}

and the following form:

{{{
#!python
class AForm(forms.ModelForm):
    class Meta:
        model = AModel
        fields = ""__all__""
}}}

I use PostgreSQL as database backend. In this case, when AForm instance is created with number's field value more than 2147483647, two error messages are created:

{{{
>>> f = AForm({'number': 1111111111111})
>>> f.is_valid()
False
>>> f.errors
{'number': [u'Ensure this value is less than or equal to 100.', u'Ensure this value is less than or equal to 2147483647.']}
}}}

In the [https://docs.djangoproject.com/en/1.9/_modules/django/db/models/fields/#IntegerField source code for IntegerField] there is code for adding MaxValueValidator and MinValueValidator:

{{{
#!python
@cached_property
    def validators(self):
        # These validators can't be added at field initialization time since
        # they're based on values retrieved from `connection`.
        range_validators = []
        internal_type = self.get_internal_type()
        min_value, max_value = connection.ops.integer_field_range(internal_type)
        if min_value is not None:
            range_validators.append(validators.MinValueValidator(min_value))
        if max_value is not None:
            range_validators.append(validators.MaxValueValidator(max_value))
        return super(IntegerField, self).validators + range_validators
}}}

So as result two MaxValueValidators and two error messages are created. I think this code should check for another similar validators before adding these ones."	Bug	closed	Database layer (models, ORM)	1.9	Normal	fixed	IntegerField, validators, MaxValueValidator		Ready for checkin	1	0	0	0	0	0
