From d5cb31219922da7ef8fcaf55f1f73dec4db69456 Mon Sep 17 00:00:00 2001
From: Norbert Biczo <pyrooka@users.noreply.github.com>
Date: Thu, 1 Jul 2021 14:43:23 +0200
Subject: [PATCH 1/4] chore: remove reserved keywords from kwargs before
 passing down

---
 ibm_cloud_sdk_core/base_service.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ibm_cloud_sdk_core/base_service.py b/ibm_cloud_sdk_core/base_service.py
index afc8275f..c04d3c12 100644
--- a/ibm_cloud_sdk_core/base_service.py
+++ b/ibm_cloud_sdk_core/base_service.py
@@ -277,6 +277,11 @@ def send(self, request: requests.Request, **kwargs) -> DetailedResponse:
         # Check to see if the caller specified the 'stream' argument.
         stream_response = kwargs.get('stream') or False
 
+        # Remove the keys we set manually, don't let the user to overwrite these.
+        reserved_keys = ['method', 'url', 'headers', 'params', 'cookies']
+        for key in reserved_keys:
+            kwargs.pop(key, None)
+
         try:
             response = self.http_client.request(**request,
                                                 cookies=self.jar,

From 5fdca87a6439c6bda8cde666db526a1765147f7f Mon Sep 17 00:00:00 2001
From: Norbert Biczo <pyrooka@users.noreply.github.com>
Date: Fri, 2 Jul 2021 12:38:50 +0200
Subject: [PATCH 2/4] chore: disable no-member pylint warnings (false positive)

---
 .pylintrc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.pylintrc b/.pylintrc
index 824cc750..840d6374 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -6,7 +6,8 @@ disable=
     duplicate-code,
     missing-module-docstring,
     too-many-arguments,
-    unnecessary-pass
+    unnecessary-pass,
+    no-member,
 
 [TYPECHECK]
 ignored-classes= responses

From 833a35452004c32c3519e7feb1f4b5f3812a6528 Mon Sep 17 00:00:00 2001
From: Norbert Biczo <pyrooka@users.noreply.github.com>
Date: Fri, 2 Jul 2021 14:55:45 +0200
Subject: [PATCH 3/4] chore: log warning if a key is removed

---
 ibm_cloud_sdk_core/base_service.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ibm_cloud_sdk_core/base_service.py b/ibm_cloud_sdk_core/base_service.py
index c04d3c12..ae9264e1 100644
--- a/ibm_cloud_sdk_core/base_service.py
+++ b/ibm_cloud_sdk_core/base_service.py
@@ -280,8 +280,9 @@ def send(self, request: requests.Request, **kwargs) -> DetailedResponse:
         # Remove the keys we set manually, don't let the user to overwrite these.
         reserved_keys = ['method', 'url', 'headers', 'params', 'cookies']
         for key in reserved_keys:
-            kwargs.pop(key, None)
-
+            if key in kwargs:
+                del kwargs[key]
+                logging.warning('"%s" has been removed from the request', key)
         try:
             response = self.http_client.request(**request,
                                                 cookies=self.jar,

From 24dddc908363b650fccd35d801768b45282206bf Mon Sep 17 00:00:00 2001
From: Norbert Biczo <pyrooka@users.noreply.github.com>
Date: Fri, 2 Jul 2021 14:58:51 +0200
Subject: [PATCH 4/4] test: add unit test for reserved keys

---
 test/test_base_service.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/test/test_base_service.py b/test/test_base_service.py
index dc6276a5..6d2d888a 100644
--- a/test/test_base_service.py
+++ b/test/test_base_service.py
@@ -685,6 +685,30 @@ def test_user_agent_header():
     assert response.get_result().request.headers.__getitem__(
         'user-agent') == user_agent_header['User-Agent']
 
+@responses.activate
+def test_reserved_keys(caplog):
+    service = AnyServiceV1('2021-07-02', authenticator=NoAuthAuthenticator())
+    responses.add(
+        responses.GET,
+        'https://gateway.watsonplatform.net/test/api',
+        status=200,
+        body='some text')
+    prepped = service.prepare_request('GET', url='', headers={'key': 'OK'})
+    response = service.send(
+        prepped,
+        headers={'key': 'bad'},
+        method='POST',
+        url='localhost',
+        cookies=None,
+        hooks={'response': []})
+    assert response.get_result().request.headers.__getitem__('key') == 'OK'
+    assert response.get_result().request.url == 'https://gateway.watsonplatform.net/test/api'
+    assert response.get_result().request.method == 'GET'
+    assert response.get_result().request.hooks == {'response': []}
+    assert caplog.record_tuples[0][2] == '"method" has been removed from the request'
+    assert caplog.record_tuples[1][2] == '"url" has been removed from the request'
+    assert caplog.record_tuples[2][2] == '"headers" has been removed from the request'
+    assert caplog.record_tuples[3][2] == '"cookies" has been removed from the request'
 
 def test_files_dict():
     service = AnyServiceV1('2018-11-20', authenticator=NoAuthAuthenticator())
