Skip to content

fix: IndexError exporting a zero-width dataset to reStructuredText - #659

Closed
santhreal wants to merge 1 commit into
jazzband:masterfrom
santhreal:fix/rst-zero-width-dataset
Closed

santhreal wants to merge 1 commit into
jazzband:masterfrom
santhreal:fix/rst-zero-width-dataset

Conversation

@santhreal

Copy link
Copy Markdown

Exporting a zero-width dataset (rows present, no columns) to rst raises IndexError. export_set guards the empty case with if not dataset.dict, but a zero-width dataset has dict == [[]] which is truthy, so it falls through to get_col(0)/column_widths[0] and indexes an empty row.

Such a dataset is valid: [[]] is valid JSON that imports cleanly (import_set sets .dict directly), and every other text format degrades gracefully (csv/tsv give a blank line, json gives [[]], html/latex give an empty table). Only rst crashes. This also returns '' when the dataset has no columns.

import tablib
tablib.import_set('[[]]', format='json').export('rst')  # IndexError before, '' after

export_set guarded the empty case with `if not dataset.dict` but a
zero-width dataset (rows present, no columns; dict == [[]]) is truthy, so
it fell through to get_col(0)/column_widths[0] and raised IndexError. Such
a dataset is valid and round-trips through JSON as '[[]]'; every other text
format degrades gracefully (csv -> '\r\n', json -> '[[]]', html/latex ->
empty table). Also return '' when the dataset has no columns.
@hugovk

hugovk commented Jul 28, 2026

Copy link
Copy Markdown
Member

You've opened many PRs across these repos two weeks ago, and then closed them with no comment:

python-humanize/humanize#352
python-humanize/humanize#353
prettytable/prettytable#483
prettytable/prettytable#484
#659
#660
#661

Please could you explain why?

Also hundreds in other repos:

image

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.

2 participants