Repository navigation
Fix Watch.stream(deserialize=False) blank lines, RV and ERROR events - #2798
Merged
kubernetes-prow[bot] merged 1 commit intoNov 22, 2026
Merged
Conversation
With deserialize=False, Watch.stream() only ran json.loads(line). A
blank line raised JSONDecodeError, the resource version was never
tracked, so reconnects replayed events or hit 410, and an ERROR event
raised KeyError('raw_object').
On this path, skip blank lines, track the resource version from the raw
dict, and read ERROR events from event['object']. Yielded events stay
plain dicts. Add unit tests for these cases.
Contributor
|
/lgtm |
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ilcm96, yliaog The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
kubernetes-prow
Bot
merged commit Nov 22, 2026
4c7c50d
into
kubernetes-client:master
10 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind bug
What this PR does / why we need it:
Follow-up to the review comment on #2778 about the
deserialize=Falsepath.Watch.stream(..., deserialize=False)only runsjson.loads()on each line, so:JSONDecodeError.Watch.resource_versionis never updated, so a reconnect reuses the initialresource_version, or the watch stops silently if none was given.ERRORevent raisesKeyError('raw_object')instead ofApiExceptionor the one-time 410 retry.E.g. watching ConfigMaps with
deserialize=False, resource_version="1"raisesKeyError: 'raw_object'instead ofApiException(410).On the
deserialize=Falsepath only, this PR skips blank lines as thedeserialize=Truepath does, tracks the non-emptyobject.metadata.resourceVersionof non-ERROR events, and reads the ERROR Status fromevent['object'].Which issue(s) this PR fixes:
None.
Special notes for your reviewer:
deserialize=True, a watch withouttimeout_secondsnow keeps reconnecting untilstop(), even if started withoutresource_version, sotest_watch_with_deserialize_paramnow callsw.stop().JSONDecodeError, as before.kubernetes/watch/watch_test.pythat fail on master. On kind, the ConfigMap watch above raisesApiException(410)andw.resource_versionfollows received events. Blank lines are covered by unit tests only.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: