Fix Protocol.UndefinedError when composite casts merge struct results - #707
Closed
MajdSehwail wants to merge 1 commit into
Closed
Fix Protocol.UndefinedError when composite casts merge struct results#707MajdSehwail wants to merge 1 commit into
MajdSehwail wants to merge 1 commit into
Conversation
Cast.AllOf merges member results with Utils.merge_maps. A oneOf or discriminator member rebuilds the matched branch as a struct, and reducing over a struct raises Protocol.UndefinedError, so any allOf wrapper around a struct-building union crashes the whole cast. merge_maps now demotes struct arguments to plain maps first; this also keeps the anyOf accumulator safe should its struct short-circuit change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #705.
Cast.Utils.merge_maps/2now demotes struct arguments to plain maps before merging.Cast.OneOf(and the discriminator path) rebuild a matched branch as its schema struct; when that result reaches anallOfmerge,Enum.reduce/3over the struct raisedProtocol.UndefinedErrorand killed the whole cast. Demoting at the merge keeps struct building intact everywhere else (v3.18.2 deliberately strengthened it), and also keeps theanyOfaccumulator safe should its struct short-circuit ever change.Regression test: an
allOfwrapper around aoneOfmember whose branch casts to a struct — the exact wrapper idiom used to attach a description or default to a referenced union. Before the fix it raisesProtocol.UndefinedError; with it, the cast returns the merged map.Full test suite: 9 doctests, 390 tests, 0 failures.
🤖 Generated with Claude Code