Raise UnsupportedFormat for a list with non-uniform row types in _set_dict - #673
Open
eeshsaxena wants to merge 1 commit into
Open
Raise UnsupportedFormat for a list with non-uniform row types in _set_dict#673eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
Conversation
_set_dict only checks the type of the first element and then assumes every row matches it. A list whose first item is a dict but a later item is not (for example a YAML list with a trailing bare '-', which parses to None) reached list(row.values()) and raised a bare AttributeError; the list-of-rows branch has the same issue and raised TypeError. Check each row and raise UnsupportedFormat, matching how other malformed input is reported.
Author
|
Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix ( |
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.
Hit this loading some YAML that came back from an external source. A list whose first item is a mapping but which contains a later non-mapping item, e.g.
(that trailing bare
-parses toNone) raisesAttributeError: 'NoneType' object has no attribute 'values'fromDataset._set_dictinstead of a tablib error._set_dictdecides the shape frompickle[0]alone and then assumes every row has that type: the dict branch doeslist(row.values())on each row, and the list-of-rows branch doesRow(row), so a later element of a different type raises a bareAttributeError(orTypeErrorfor the list branch) rather than theUnsupportedFormatthat malformed input normally gets. I added a per-row type check to both branches.Added a test next to the existing YAML import tests; it fails on master with the AttributeError and passes with the change, and the dict/yaml/json/csv tests still pass. Found it while fuzzing the format importers with mutated input.