Repository navigation
Tolerate objects that do not fit the model in list() and watch() - #35
Merged
Merged
Conversation
Add invalid=InvalidObjects.INCLUDE to Api.list() and Api.watch(). An object that fails validation comes back as an InvalidObject (raw data, the ValidationError, parsed metadata): in ListWithInvalid.invalid for list(), or as an InvalidWatchEvent for watch(), which keeps streaming. Only ADDED/MODIFIED/DELETED objects whose metadata parses with a name are tolerated; ERROR events, unparseable bookmarks and corrupt lines still raise. Overloads keep the return types of existing calls unchanged. Add WatchEvent.is_initial_events_end for the bookmark that ends a send_initial_events watch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Test PyPI packages publishedThe following packages have been published to Test PyPI:
Install with: |
The tolerant list path parsed the body with json.loads, so a body that is not JSON or not UTF-8 raised JSONDecodeError/UnicodeDecodeError instead of the ValidationError the default mode and the Api.list() docstring promise. Fall back to the strict list model's model_validate_json in that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Test PyPI packages publishedThe following packages have been published to Test PyPI:
Install with: |
This branch was successfully deployed
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.
Summary
One object that fails validation (typically a custom resource stored before its CRD schema changed) currently fails a whole
list()and ends awatch(). Reconnecting doesn't help because the same object comes back. This adds an opt-in mode that keeps such objects instead of raising.Changes
InvalidObjectsenum (RAISEdefault,INCLUDE) inkubex.core.params; the strings"raise"/"include"are accepted too, matchingVersionMatchand friends. Overloads onApi.list()/Api.watch()pick the return type, so existing callers' types are unchanged.InvalidObject(raw,error, parsedmetadata) andListWithInvalid(aListEntitysubclass withinvalid, which is not serialized) in the newkubex.core.invalid_object.InvalidWatchEvent: hastypeandobject.metadatalikeWatchEvent, so code that tracks names or resume points works on both.INCLUDE:ERRORevents, bookmarks that don't parse, lines that aren't JSON, and objects whose metadata has no name (they can't be identified, e.g. to drop from a cache).WatchEvent.is_initial_events_endfor thek8s.io/initial-events-endbookmark.MetadataAccessor.watchis unchanged:PartialObjectMetadatahas only optional fields.Not in this PR
get/delete/patch/replacestill parse with the model, so on a bad object they raiseValidationError, the last three after the server has applied the change. Documented, withapi.metadataas the workaround.ValidationErrorunwrapped; wrapping it in a kubex exception would be a breaking change.Testing
test/test_invalid_objects.py): parsing rules,Api.list/Api.watchvia the stub client,is_initial_events_end, andassert_typechecks of the overloads.test/e2e/test_invalid_objects.py): a CRD object the model rejects, through watch and list (including a DELETED event for it), and resuming from the end bookmark's resource version.mkdocs build --strictare clean.🤖 Generated with Claude Code