Skip to content

Fix Watch.stream(deserialize=False) blank lines, RV and ERROR events - #2798

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
ilcm96:watch-raw-events
Nov 22, 2026
Merged

kubernetes-prow[bot] merged 1 commit into
kubernetes-client:masterfrom
ilcm96:watch-raw-events

Conversation

@ilcm96

@ilcm96 ilcm96 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

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=False path. Watch.stream(..., deserialize=False) only runs json.loads() on each line, so:

  1. A blank line raises JSONDecodeError.
  2. Watch.resource_version is never updated, so a reconnect reuses the initial resource_version, or the watch stops silently if none was given.
  3. An ERROR event raises KeyError('raw_object') instead of ApiException or the one-time 410 retry.

E.g. watching ConfigMaps with deserialize=False, resource_version="1" raises KeyError: 'raw_object' instead of ApiException(410).

On the deserialize=False path only, this PR skips blank lines as the deserialize=True path does, tracks the non-empty object.metadata.resourceVersion of non-ERROR events, and reads the ERROR Status from event['object'].

Which issue(s) this PR fixes:

None.

Special notes for your reviewer:

  • Like deserialize=True, a watch without timeout_seconds now keeps reconnecting until stop(), even if started without resource_version, so test_watch_with_deserialize_param now calls w.stop().
  • Non-blank invalid JSON still raises JSONDecodeError, as before.
  • Tested with new unit tests in kubernetes/watch/watch_test.py that fail on master. On kind, the ConfigMap watch above raises ApiException(410) and w.resource_version follows received events. Blank lines are covered by unit tests only.

Does this PR introduce a user-facing change?

`Watch.stream(deserialize=False)` no longer raises on blank lines or ERROR events and resumes from the last received resourceVersion, so like `deserialize=True` it keeps reconnecting until `stop()` when `timeout_seconds` is not set.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


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.
@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Nov 21, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog November 21, 2026 10:01
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 21, 2026
@yliaog

yliaog commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 22, 2026
@kubernetes-prow

Copy link
Copy Markdown
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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 22, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 4c7c50d into kubernetes-client:master Nov 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants