Skip to content

fix: use the first column as the default LabelValueTable label - #152

Merged
harro merged 1 commit into
google:masterfrom
0z5a:fix/labelvaluetable-default-label
Nov 16, 2026
Merged

harro merged 1 commit into
google:masterfrom
0z5a:fix/labelvaluetable-default-label

Conversation

@0z5a

@0z5a 0z5a commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

TextTable.LabelValueTable() says it uses the first column as the label when label_list is None. The default was set to self._Header()[0], which is the column name itself, a string. The validation loop and the header in label_list check then work on single characters. Any table whose first column name is longer than one character raises TableError: Invalid label prefix: <first letter>.:

from textfsm import texttable

t = texttable.TextTable()
t.header = ('Interface', 'Status')
t.Append(('ge-0/0/0', 'up'))
print(t.LabelValueTable())
# textfsm.texttable.TableError: Invalid label prefix: I.

CliTable.LabelValueTable() falls back to this default when the template has no Key values, so it fails the same way.

This change wraps the default in a list, so LabelValueTable() gives the same output as LabelValueTable([<first column>]). Explicit label_list arguments behave as before.

The existing testTableWithLabels uses a first column named a, which hides the problem. The new test uses multi-character column names. It checks the expected output and that the default matches the explicit first-column call.

Testing:

  • New test fails before the fix (TableError: Invalid label prefix: I.) and passes after it.
  • pytest tests: 109 passed, 28 subtests passed. The two existing FutureWarnings from clitable.py are unchanged.
  • git diff --check is clean.

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

LabelValueTable() is documented to use the first column as the label
when label_list is None, but the default was the first column name
itself, a string. The validation loop then iterated over its
characters, so any table whose first column name is longer than one
character raised "TableError: Invalid label prefix: <first letter>.".
CliTable.LabelValueTable() falls back to the same default when the
template has no Key values.

Wrap the default in a list and add a test with multi-character
column names.
@harro
harro merged commit 80b43ea into google:master Nov 16, 2026
6 checks passed
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