Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tablib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def _set_dict(self, pickle):
self.wipe()
self.headers = list(pickle[0].keys())
for row in pickle:
if not isinstance(row, dict):
raise UnsupportedFormat(error_details)
self.append(Row(list(row.values())))
else:
raise UnsupportedFormat(error_details)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ def test_book_export_no_exceptions(self):
unsupported = ['csv', 'tsv', 'jira', 'latex', 'df']
self._test_export_data_in_all_formats(book, exclude=unsupported)

def test_dict_setter_with_non_dict_row(self):
# A list whose first item is a dict but which contains a non-dict item
# (e.g. from YAML "- null" or JSON "[{...}, null]") used to raise a bare
# AttributeError instead of UnsupportedFormat.
data = tablib.Dataset()
with self.assertRaises(UnsupportedFormat):
data.dict = [{'a': 1}, None]
with self.assertRaises(UnsupportedFormat):
tablib.import_set('[{"a": 1}, null]', format='json')

def test_book_unsupported_loading(self):
with self.assertRaises(UnsupportedFormat):
tablib.Databook().load('Any stream', 'csv')
Expand Down