Skip to content

Commit

Permalink
Ensure no invalid min_length/min_value/max_value arguments. Closes #2369
Browse files Browse the repository at this point in the history
.
  • Loading branch information
tomchristie committed Jan 5, 2015
1 parent f8e310f commit 8cf3744
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rest_framework/utils/field_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import inspect


NUMERIC_FIELD_TYPES = (
models.IntegerField, models.FloatField, models.DecimalField
)


class ClassLookupDict(object):
"""
Takes a dictionary with classes as keys.
Expand Down Expand Up @@ -119,7 +124,7 @@ def get_field_kwargs(field_name, model_field):
validator.limit_value for validator in validator_kwarg
if isinstance(validator, validators.MinLengthValidator)
), None)
if min_length is not None:
if min_length is not None and isinstance(model_field, models.CharField):
kwargs['min_length'] = min_length
validator_kwarg = [
validator for validator in validator_kwarg
Expand All @@ -132,7 +137,7 @@ def get_field_kwargs(field_name, model_field):
validator.limit_value for validator in validator_kwarg
if isinstance(validator, validators.MaxValueValidator)
), None)
if max_value is not None:
if max_value is not None and isinstance(model_field, NUMERIC_FIELD_TYPES):
kwargs['max_value'] = max_value
validator_kwarg = [
validator for validator in validator_kwarg
Expand All @@ -145,7 +150,7 @@ def get_field_kwargs(field_name, model_field):
validator.limit_value for validator in validator_kwarg
if isinstance(validator, validators.MinValueValidator)
), None)
if min_value is not None:
if min_value is not None and isinstance(model_field, NUMERIC_FIELD_TYPES):
kwargs['min_value'] = min_value
validator_kwarg = [
validator for validator in validator_kwarg
Expand Down

0 comments on commit 8cf3744

Please sign in to comment.