Fix data-dependent flip_array dtype check in all add_* methods#103
Merged
Conversation
In add_persistent_vector, add_persistent_array, add_dynamic_vector, and add_dynamic_array the WrongDatatype check on flip_array was nested inside `if flip_array.sum():`, so a non-bool flip array with all-zero/falsy values silently passed validation while the same dtype with any truthy value raised an error. The validity of an array's dtype must not depend on its contents. Fix: hoist the dtype check to the top of the `if flip_array is not None:` block in all four methods, before the sum() guard that decides whether to write the resource. Also fix add_dynamic_array's early-exit pre-clearing logic (`if not flip_array.sum(): flip_array = None`) to validate dtype before discarding the array. Adds four regression tests covering the previously-silent all-zeros case for each of the four affected methods.
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
add_persistent_vector,add_persistent_array,add_dynamic_vector, andadd_dynamic_array, theWrongDatatypecheck onflip_arraywas nested insideif flip_array.sum():— so a non-bool flip array with all-zero/falsy values silently passed validation, while the identical dtype with any truthy value raised an erroradd_dynamic_array's early-exit pre-clearing (if not flip_array.sum(): flip_array = None), which discarded a non-bool all-zeros array without ever checking its dtypeif flip_array is not None:block in all four methods, before thesum()guard that decides whether to write the resourceTest plan
test_add_*_flip_dtype_all_zeros) covering the previously-silent all-zeros non-bool case for each affected methodtest_datapackage.pysuite: 54 passed