Skip to content

Commit

Permalink
actually convert request_compression_min_size_bytes to int and some m…
Browse files Browse the repository at this point in the history
…ore formatting fixes
  • Loading branch information
davidlm committed Jul 25, 2023
1 parent ebcd98b commit ccd81fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
25 changes: 13 additions & 12 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,12 @@ def _compute_request_compression_config(self, config_kwargs):
min_size = self._config_store.get_config_variable(
'request_min_compression_size_bytes'
)
config_kwargs['request_min_compression_size_bytes'] = min_size
# conversion func is skipped so input validation must be done here
# regardless if the value is coming from the config store or the
# config object
self._validate_min_compression_size(min_size)
min_size = self._validate_min_compression_size(min_size)
config_kwargs['request_min_compression_size_bytes'] = min_size

if disabled is None:
disabled = self._config_store.get_config_variable(
'disable_request_compression'
Expand All @@ -582,19 +583,19 @@ def _validate_min_compression_size(self, min_size):
try:
min_size = int(min_size)
except (ValueError, TypeError):
raise botocore.exceptions.InvalidConfigError(
error_msg=(
f'{error_msg_base} Value must be an integer. '
f'Received {type(min_size)} instead.'
)
msg = (
f'{error_msg_base} Value must be an integer. '
f'Received {type(min_size)} instead.'
)
raise botocore.exceptions.InvalidConfigError(error_msg=msg)
if not min_allowed_min_size <= min_size <= max_allowed_min_size:
raise botocore.exceptions.InvalidConfigError(
error_msg=(
f'{error_msg_base} Value must be between '
f'{min_allowed_min_size} and {max_allowed_min_size}.'
)
msg = (
f'{error_msg_base} Value must be between '
f'{min_allowed_min_size} and {max_allowed_min_size}.'
)
raise botocore.exceptions.InvalidConfigError(error_msg=msg)

return min_size

def _ensure_boolean(self, val):
if isinstance(val, bool):
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,12 @@ def test_request_compression_client_config_overrides_config_store(self):
self.assertEqual(config.request_min_compression_size_bytes, 1)
self.assertFalse(config.disable_request_compression)

def test_coercible_value_request_min_compression_size_bytes(self):
config = Config(request_min_compression_size_bytes='100')
client_args = self.call_get_client_args(client_config=config)
config = client_args['client_config']
self.assertEqual(config.request_min_compression_size_bytes, 100)

def test_bad_type_request_min_compression_size_bytes(self):
with self.assertRaises(exceptions.InvalidConfigError):
config = Config(request_min_compression_size_bytes='foo')
Expand Down

0 comments on commit ccd81fa

Please sign in to comment.