fix(property): do not mutate schemas when normalizing union types - #258
Open
fede-kamel wants to merge 1 commit into
Open
fix(property): do not mutate schemas when normalizing union types#258fede-kamel wants to merge 1 commit into
fede-kamel wants to merge 1 commit into
Conversation
_normalize_json_schema_union_types reused the schema's own anyOf list as the accumulator of normalized types, so comparing or checking the castability of a schema combining a `type` list with `anyOf` appended the entries of `type` to the schema's anyOf. The normalized types are now accumulated in a copy. Signed-off-by: Federico Kamelhar <federico.kamelhar@oracle.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 #254.
Root cause
_normalize_json_schema_union_typesinproperty.pyusedschema.get("anyOf", [])as the accumulator of normalized types and appended the entries of thetypelist to it. When the schema already had ananyOflist, the appends went into the caller's list, so everyjson_schemas_have_same_type/json_schema_is_castable_to/value_is_of_compatible_typecall on such a schema grew itsanyOf. These functions run duringFlowandDataFlowEdgevalidation, so aProperty.json_schemacould change as a side effect of building a flow.Changes
property.py: accumulate the normalized types in a copy of theanyOflist.tests/test_properties.py: regression test comparing a schema that combines atypelist withanyOfseveral times and asserting both schemas are unchanged. Fails onmain, passes with the fix.Verification
pytest tests/test_properties.py: 177 passed, 2 skipped. Full suite: 1180 passed, 586 skipped (SKIP_LLM_TESTS=1).tests/run_tests.sh) reproduced locally on Python 3.10 through 3.14.