-
Notifications
You must be signed in to change notification settings - Fork 77
Fix parsing of bookmark objects #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes a bug in the parsing of bookmark events so that bookmark resource versions are correctly obtained from the original (raw) JSON object. Key changes include updates to the test assertions in watch_test.py and modifications in watch.py to extract resourceVersion from raw_object for bookmark events.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
kubernetes_asyncio/watch/watch_test.py | Updated assertions to use raw_object for resourceVersion verification |
kubernetes_asyncio/watch/watch.py | Adjusted unmarshal_event to correctly access resourceVersion for bookmark events |
Comments suppressed due to low confidence (1)
kubernetes_asyncio/watch/watch_test.py:392
- [nitpick] The test now checks 'raw_object' instead of 'object'; ensure that additional test cases are in place to cover scenarios where the deserialized object may be used, ensuring full coverage of both bookmark and non-bookmark events.
self.assertTrue(isinstance(event['raw_object'], dict))
self.resource_version = js['raw_object']['metadata']['resourceVersion'] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For bookmark events, ensure that js['raw_object'] always contains a 'metadata' key with 'resourceVersion' to avoid potential KeyErrors. Consider adding a conditional check if there's any chance that this field might be missing.
self.resource_version = js['raw_object']['metadata']['resourceVersion'] | |
if ('metadata' in js['raw_object'] and | |
'resourceVersion' in js['raw_object']['metadata']): | |
self.resource_version = js['raw_object']['metadata']['resourceVersion'] | |
else: | |
raise Exception(("Malformed JSON response for bookmark event, " | |
"'metadata' or 'resourceVersion' field is missing. " | |
"JSON: {}").format(js)) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add some checks for malformed events, similar are for standard events.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #364 +/- ##
=======================================
Coverage 27.06% 27.06%
=======================================
Files 805 805
Lines 98720 98727 +7
=======================================
+ Hits 26717 26724 +7
Misses 72003 72003 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
self.resource_version = js['raw_object']['metadata']['resourceVersion'] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add some checks for malformed events, similar are for standard events.
What is this MR?
This MR fixes the bug described in #363, and includes a test to show it's working. It's arguably a breaking change, because bookmark objects will no longer contain a parsed
object
fields, but I would argue that this is fine because the parsing didn't work anyway, so it's unlikely anyone was relying on this.There are other ways of fixing this, such as handling bookmarks early and short-circuiting, but I decided to go for more minimal changes to the unmarshal logic.
How is this tested?
I added a test which includes a real payload from a bookmark event obtained when watching a kubernetes namespace, which previously would cause the client to crash.
I tested this manually by running the
bookmark_bug.py
script described in the issue, and got the expected output: