Skip to content

Commit 7d11519

Browse files
authored
Fix content-type detection for object sending as patch (#334)
1 parent 27c76b6 commit 7d11519

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

kubernetes_asyncio/client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def select_header_content_type(self, content_types, method=None, body=None):
540540
isinstance(body, list)):
541541
return 'application/json-patch+json'
542542
if ('application/strategic-merge-patch+json' in content_types and
543-
isinstance(body, dict)):
543+
(isinstance(body, dict) or hasattr(body, "to_dict"))):
544544
return 'application/strategic-merge-patch+json'
545545

546546
if 'application/json' in content_types or '*/*' in content_types:

kubernetes_asyncio/e2e_test/test_apply_patch.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ async def test_apply_patch(self):
5050
)
5151
self.assertEqual(name, resp.metadata.name)
5252

53-
resp = await api.read_namespaced_config_map(name=name, namespace="default")
54-
self.assertEqual(name, resp.metadata.name)
53+
cm = await api.read_namespaced_config_map(name=name, namespace="default")
54+
self.assertEqual(name, cm.metadata.name)
55+
56+
# strategic merge patch for object
57+
cm.data["new"] = "value"
58+
resp = await api.patch_namespaced_config_map(
59+
field_manager="test",
60+
body=cm,
61+
name=name,
62+
namespace="default",
63+
)
64+
self.assertEqual(resp.data, {'hello': 'world!', 'new': 'value'})
5565

5666
resp = await api.delete_namespaced_config_map(
5767
name=name, body={}, namespace="default"

scripts/api_client_strategic_merge_patch.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
+ isinstance(body, list)):
1414
+ return 'application/json-patch+json'
1515
+ if ('application/strategic-merge-patch+json' in content_types and
16-
+ isinstance(body, dict)):
16+
+ (isinstance(body, dict) or hasattr(body, "to_dict"))):
1717
+ return 'application/strategic-merge-patch+json'
1818

1919
if 'application/json' in content_types or '*/*' in content_types:

0 commit comments

Comments
 (0)