fix: tuple/list dict keys cross-match when elements overlap (fixes #312)#351
Open
gaoflow wants to merge 1 commit into
Open
fix: tuple/list dict keys cross-match when elements overlap (fixes #312)#351gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
…dation
Schema keys that are tuples or lists were validated through the
ITERABLE path which uses Or semantics on elements. When two tuple
keys had overlapping elements (e.g. ('a','b') and ('b','b')),
the first key would incorrectly match the second data key because
Or('a','b') matches all elements of ('b','b').
Fix by using exact comparison for tuple/list schema keys during
dict key matching, matching the expectation that dict keys should
be compared literally rather than as sets of allowed values.
Fixes keleshev#312
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.
Tuple/list dict keys cross-match when elements overlap because
Schema(skey).validate(key)treats tuple keys as ITERABLE, buildingOr(*elements)semantics. Two distinct tuple keys with overlappingelements (e.g.
('a','b')and('b','b')) interfere — the firstgreedily matches the second data key.
Fixes #312.
Root cause: In
Schema.validateDICT flavor, tuple/list keys arerouted through the ITERABLE validation path which builds
Or(*elements),turning key matching into set-membership instead of exact literal
comparison.
Fix (+11/-1): When a schema key is tuple/list, compare exactly
(
skey == key) instead of routing throughSchema(skey).validate(key).Non-tuple/list keys (strings, Optional, Or, And, Regex, etc.) continue
through the normal validation path unchanged.
120/120 tests pass.
This pull request was prepared with the assistance of AI, under my
direction and review.