diff --git a/.changes/next-release/bugfix-Validator-69448.json b/.changes/next-release/bugfix-Validator-69448.json new file mode 100644 index 0000000000..95e3791e59 --- /dev/null +++ b/.changes/next-release/bugfix-Validator-69448.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "Validator", + "description": "Fix showing incorrect max-value in error message for range and length value validation" +} diff --git a/botocore/validate.py b/botocore/validate.py index 37b999367a..ccd0feb0f6 100644 --- a/botocore/validate.py +++ b/botocore/validate.py @@ -70,7 +70,6 @@ def _type_check(param, errors, name): def range_check(name, value, shape, error_type, errors): failed = False min_allowed = float('-inf') - max_allowed = float('inf') if 'min' in shape.metadata: min_allowed = shape.metadata['min'] if value < min_allowed: @@ -82,8 +81,7 @@ def range_check(name, value, shape, error_type, errors): if value < min_allowed: failed = True if failed: - errors.report(name, error_type, param=value, - valid_range=[min_allowed, max_allowed]) + errors.report(name, error_type, param=value, min_allowed=min_allowed) class ValidationErrors(object): @@ -117,17 +115,15 @@ def _format_error(self, error): str(type(additional['param'])), ', '.join(additional['valid_types'])) elif error_type == 'invalid range': - min_allowed = additional['valid_range'][0] - max_allowed = additional['valid_range'][1] - return ('Invalid range for parameter %s, value: %s, valid range: ' - '%s-%s' % (name, additional['param'], - min_allowed, max_allowed)) + min_allowed = additional['min_allowed'] + return ('Invalid value for parameter %s, value: %s, ' + 'valid min value: %s' % (name, additional['param'], + min_allowed)) elif error_type == 'invalid length': - min_allowed = additional['valid_range'][0] - max_allowed = additional['valid_range'][1] - return ('Invalid length for parameter %s, value: %s, valid range: ' - '%s-%s' % (name, additional['param'], - min_allowed, max_allowed)) + min_allowed = additional['min_allowed'] + return ('Invalid length for parameter %s, value: %s, ' + 'valid min length: %s' % (name, additional['param'], + min_allowed)) elif error_type == 'unable to encode to json': return 'Invalid parameter %s must be json serializable: %s' \ % (name, additional['type_error']) diff --git a/tests/unit/test_validate.py b/tests/unit/test_validate.py index 88e809f250..fab8544d26 100644 --- a/tests/unit/test_validate.py +++ b/tests/unit/test_validate.py @@ -278,8 +278,8 @@ def test_less_than_range(self): 'Long': -10, }, errors=[ - 'Invalid range for parameter Int', - 'Invalid range for parameter Long', + 'Invalid value for parameter Int', + 'Invalid value for parameter Long', ] ) @@ -423,7 +423,7 @@ def test_range_float(self): 'Float': 1, }, errors=[ - 'Invalid range for parameter Float', + 'Invalid value for parameter Float', ] ) @@ -441,7 +441,7 @@ def test_decimal_still_validates_range(self): 'Float': decimal.Decimal('1'), }, errors=[ - 'Invalid range for parameter Float', + 'Invalid value for parameter Float', ] )