jazzband / prettytable

Display tabular data in a visually appealing ASCII table format
https://pypi.org/project/PrettyTable/
Other
1.36k stars 155 forks source link

PrettyTable 3.1.0 regression on _stringify_row #166

Closed michal-jagiello-tmpl closed 2 years ago

michal-jagiello-tmpl commented 2 years ago

What did you do?

Trying to get string of my PrettyTable instance

What did you expect to happen?

Get the string

What actually happened?

Traceback (most recent call last):
  File "/home/ubuntu/onap/repos/xtesting-onap/doc/generate_status.py", line 428, in <module>
    write_file.write(str(dashboard_table))
  File "/home/ubuntu/onap/repos/xtesting-onap/.virtualenv/lib/python3.10/site-packages/prettytable/prettytable.py", line 319, in __str__
    return self.get_string()
  File "/home/ubuntu/onap/repos/xtesting-onap/.virtualenv/lib/python3.10/site-packages/prettytable/prettytable.py", line 1687, in get_string
    lines.append(self._stringify_row(row, options, self._hrule))
  File "/home/ubuntu/onap/repos/xtesting-onap/.virtualenv/lib/python3.10/site-packages/prettytable/prettytable.py", line 1833, in _stringify_row
    if line == "None" and self.none_format[field] is not None:
KeyError: 'Status'

For the version 3.0.0 works fine

What versions are you using?

Please include code that reproduces the issue.

LOGGER.info(dashboard_table)

and

write_file.write(str(dashboard_table))

The best reproductions are self-contained scripts with minimal dependencies.

from prettytable import PrettyTable
t = PrettyTable()
t.add_row(["value 1", "None", "value 2"])
assert (
            t.get_string().strip()
            == """
+---------+---------+---------+
| Field 1 | Field 2 | Field 3 |
+---------+---------+---------+
| value 1 |   None  | value 2 |
+---------+---------+---------+
""".strip()
)
michal-jagiello-tmpl commented 2 years ago

That happens when

line == "None"

and I think there is missing test for that

michal-jagiello-tmpl commented 2 years ago

I did a workaround by set

my_awesome_prettytable.none_format["Status"] = "None"
xuyixin1996 commented 2 years ago

I encounter the same issue and I revert to use 3.0.0 the fix looks good

hugovk commented 2 years ago

Thanks both, released in 3.1.1.