Fix inverted pattern containment check & Expand validator test coverage#325
Merged
Fix inverted pattern containment check & Expand validator test coverage#325
Conversation
Replace merge_dicts-based pattern check in validate_FHIR_element_pattern() with a correct is_dict_subset() check. The old approach produced false positives when an element's list field held different primitive values from the pattern, because merge_lists() always kept values from the first (element) dict. - Add is_dict_subset() to utils.py; remove merge_dicts() - Update validate_FHIR_element_pattern() to use is_dict_subset(pattern, element) - Unify FHIRBaseModel/dict/scalar handling into a single branch - Add full unit test coverage for all validator functions - Add regression tests covering the false-positive and false-negative cases from #317
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.
This PR fixes a false-positive bug in
validate_FHIR_element_pattern()(issue #317) where elements with list fields holding values that contradict the pattern were incorrectly accepted. It replaces the brokenmerge_dicts-based containment check with a newis_dict_subset()utility, and adds full unit test coverage for all previously untested validator functions along with regression tests that directly reproduce the reported bug.Added
is_dict_subset(subset, superset)utility function in utils.py to recursively check that all keys and values insubsetare present and matching insuperset, with correct handling of nested dicts and lists of primitives.Changed
validate_FHIR_element_pattern()to useis_dict_subset(_pattern, _element)instead ofmerge_dicts(_element, _pattern) == _elementto ensure that pattern containment is properly executed. Fixesvalidate_FHIR_element_pattern()containment check is inverted #317Removed
merge_dicts()utility function.Testing
_validate_FHIR_element_constraintvalidate_FHIR_element_patternvalidate_FHIR_model_patternvalidate_FHIR_element_fixed_valuevalidate_FHIR_model_fixed_valuevalidate_type_choice_elementvalidate_slicing_cardinalitiesget_type_choice_value_by_base.