Repository: boto/botocore
Pull request #905 (2016-04-30 00:16:17)

Add session var to disable parameter validation
Corresponds to the same value in the client Config object.
This can now be specified in ``~/.aws/config``.

Alternative to https://github.com/aws/aws-cli/pull/1943

cc @kyleknap @JordonPhillips 


Patch:
diff --git a/botocore/client.py b/botocore/client.py
index ebda5db07..a2f368463 100644
--- a/botocore/client.py
+++ b/botocore/client.py
@@ -165,8 +165,12 @@ class ClientCreator(object):
         service_name = service_model.endpoint_prefix
         protocol = service_model.metadata['protocol']
         parameter_validation = True
-        if client_config:
-            parameter_validation = client_config.parameter_validation
+        if client_config and not client_config.parameter_validation:
+            parameter_validation = False
+        elif scoped_config:
+            raw_value = str(scoped_config.get('parameter_validation', ''))
+            if raw_value.lower() == 'false':
+                parameter_validation = False
         serializer = botocore.serialize.create_serializer(
             protocol, parameter_validation)
 
diff --git a/botocore/session.py b/botocore/session.py
index 2031a26d6..e06b59b58 100644
--- a/botocore/session.py
+++ b/botocore/session.py
@@ -98,6 +98,7 @@ class Session(object):
         'metadata_service_num_attempts': (
             'metadata_service_num_attempts',
             'AWS_METADATA_SERVICE_NUM_ATTEMPTS', 1, int),
+        'parameter_validation': ('parameter_validation', None, True, None),
     }
 
     #: The default format string to use when configuring the botocore logger.


Test patch:
diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py
index 16e675d83..72fa56cde 100644
--- a/tests/unit/test_client.py
+++ b/tests/unit/test_client.py
@@ -130,6 +130,17 @@ class TestAutoGeneratedClient(unittest.TestCase):
             response_parser_factory)
         return creator
 
+    def assert_no_param_error_raised(self, client):
+        try:
+            self.make_api_call_with_missing_param(client)
+        except ParamValidationError:
+            self.fail("ParamValidationError shouldn't be raised "
+                      "with validation disabled")
+
+    def make_api_call_with_missing_param(self, service_client):
+        # Missing required 'Foo' param.
+        service_client.test_operation(Bar='two')
+
     def test_client_name(self):
         creator = self.create_client_creator()
         service_client = creator.create_client(
@@ -517,7 +528,7 @@ class TestAutoGeneratedClient(unittest.TestCase):
         service_client = creator.create_client(
             'myservice', 'us-west-2', credentials=self.credentials)
         with self.assertRaises(ParamValidationError):
-            self._do_operation_with_invalid_parameters(service_client)
+            self.make_api_call_with_missing_param(service_client)
 
     def test_client_doesnt_validate_params_when_validation_disabled(self):
         creator = self.create_client_creator()
@@ -525,16 +536,28 @@ class TestAutoGeneratedClient(unittest.TestCase):
         client_config = botocore.config.Config()
         client_config.parameter_validation = False
         service_client = creator.create_client(
-            'myservice', 'us-west-2', credentials=self.credentials, client_config=client_config)
+            'myservice', 'us-west-2', credentials=self.credentials,
+            client_config=client_config)
 
-        try:
-            self._do_operation_with_invalid_parameters(service_client)
-        except ParamValidationError:
-            self.fail("ParamValidationError shouldn't be raised with validation disabled")
+        self.assert_no_param_error_raised(service_client)
+
+    def test_can_disable_param_validation_from_scoped_config(self):
+        creator = self.create_client_creator()
+        service_client = creator.create_client(
+            'myservice', 'us-west-2', credentials=self.credentials,
+            scoped_config={'parameter_validation': False})
+        self.assert_no_param_error_raised(service_client)
+
+    def test_client_config_trumps_scoped_config(self):
+        creator = self.create_client_creator()
+        scoped_config = {'parameter_validation': True}
+        client_config = botocore.config.Config(parameter_validation=False)
+        # Client config should win and param validation is disabled.
+        service_client = creator.create_client(
+            'myservice', 'us-west-2', credentials=self.credentials,
+            scoped_config=scoped_config, client_config=client_config)
+        self.assert_no_param_error_raised(service_client)
 
-    def _do_operation_with_invalid_parameters(self, service_client):
-        # Missing required 'Foo' param.
-        service_client.test_operation(Bar='two')
 
     def test_client_with_custom_both_timeout(self):
         self.create_client_creator().create_client(