Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 10ae476

Browse files
committed
quick fix of decoding error for BOOKMARK event
1 parent db50d02 commit 10ae476

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

watch/watch.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ def get_watch_argument_name(self, func):
9696
def unmarshal_event(self, data, return_type):
9797
js = json.loads(data)
9898
js['raw_object'] = js['object']
99-
if return_type and js['type'] != 'ERROR':
99+
# BOOKMARK event is treated the same as ERROR for a quick fix of
100+
# decoding exception
101+
# TODO: make use of the resource_version in BOOKMARK event for more
102+
# efficient WATCH
103+
if return_type and js['type'] != 'ERROR' and js['type'] != 'BOOKMARK':
100104
obj = SimpleNamespace(data=json.dumps(js['raw_object']))
101105
js['object'] = self._api_client.deserialize(obj, return_type)
102106
if hasattr(js['object'], 'metadata'):

watch/watch_test.py

+13
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,19 @@ def test_unmarshal_with_custom_object(self):
255255
self.assertEqual("1", event['object']['metadata']['resourceVersion'])
256256
self.assertEqual("1", w.resource_version)
257257

258+
def test_unmarshal_with_bookmark(self):
259+
w = Watch()
260+
event = w.unmarshal_event(
261+
'{"type":"BOOKMARK","object":{"kind":"Job","apiVersion":"batch/v1"'
262+
',"metadata":{"resourceVersion":"1"},"spec":{"template":{'
263+
'"metadata":{},"spec":{"containers":null}}},"status":{}}}',
264+
'V1Job')
265+
self.assertEqual("BOOKMARK", event['type'])
266+
# Watch.resource_version is *not* updated, as BOOKMARK is treated the
267+
# same as ERROR for a quick fix of decoding exception,
268+
# resource_version in BOOKMARK is *not* used at all.
269+
self.assertEqual(None, w.resource_version)
270+
258271
def test_watch_with_exception(self):
259272
fake_resp = Mock()
260273
fake_resp.close = Mock()

0 commit comments

Comments
 (0)