Skip to content

Raise UnsupportedFormat for a list with non-uniform row types in _set_dict - #673

Open
eeshsaxena wants to merge 1 commit into
jazzband:masterfrom
eeshsaxena:fix/set-dict-non-uniform-rows
Open

Raise UnsupportedFormat for a list with non-uniform row types in _set_dict#673
eeshsaxena wants to merge 1 commit into
jazzband:masterfrom
eeshsaxena:fix/set-dict-non-uniform-rows

Conversation

@eeshsaxena

Copy link
Copy Markdown

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.

- {id: 0, name: n0}
- {id: 1, name: n1}
-

(that trailing bare - parses to None) raises AttributeError: 'NoneType' object has no attribute 'values' from Dataset._set_dict instead of a tablib error.

_set_dict decides the shape from pickle[0] alone and then assumes every row has that type: the dict branch does list(row.values()) on each row, and the list-of-rows branch does Row(row), so a later element of a different type raises a bare AttributeError (or TypeError for the list branch) rather than the UnsupportedFormat that 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.

_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.
@eeshsaxena

Copy link
Copy Markdown
Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Raise UnsupportedFormat for a list with non-uniform row types in _set_dict), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining tablib!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant