Skip to content

Commit

Permalink
Fix content-type detection for object sending as patch (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomplus authored Aug 31, 2024
1 parent 27c76b6 commit 7d11519
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kubernetes_asyncio/client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def select_header_content_type(self, content_types, method=None, body=None):
isinstance(body, list)):
return 'application/json-patch+json'
if ('application/strategic-merge-patch+json' in content_types and
isinstance(body, dict)):
(isinstance(body, dict) or hasattr(body, "to_dict"))):
return 'application/strategic-merge-patch+json'

if 'application/json' in content_types or '*/*' in content_types:
Expand Down
14 changes: 12 additions & 2 deletions kubernetes_asyncio/e2e_test/test_apply_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ async def test_apply_patch(self):
)
self.assertEqual(name, resp.metadata.name)

resp = await api.read_namespaced_config_map(name=name, namespace="default")
self.assertEqual(name, resp.metadata.name)
cm = await api.read_namespaced_config_map(name=name, namespace="default")
self.assertEqual(name, cm.metadata.name)

# strategic merge patch for object
cm.data["new"] = "value"
resp = await api.patch_namespaced_config_map(
field_manager="test",
body=cm,
name=name,
namespace="default",
)
self.assertEqual(resp.data, {'hello': 'world!', 'new': 'value'})

resp = await api.delete_namespaced_config_map(
name=name, body={}, namespace="default"
Expand Down
2 changes: 1 addition & 1 deletion scripts/api_client_strategic_merge_patch.diff
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
+ isinstance(body, list)):
+ return 'application/json-patch+json'
+ if ('application/strategic-merge-patch+json' in content_types and
+ isinstance(body, dict)):
+ (isinstance(body, dict) or hasattr(body, "to_dict"))):
+ return 'application/strategic-merge-patch+json'

if 'application/json' in content_types or '*/*' in content_types:
Expand Down

0 comments on commit 7d11519

Please sign in to comment.