Skip to content

Device-only CSV inventory crashes during optional flags check #21

Open

Description

@vinsymoyya

On current master (f15c05543241e5faa482d0fae0c2244d456091b7), a CSV inventory containing only the mandatory device column crashes while parsing its first row.

from io import StringIO
from absl import flags
from tcli import inventory_csv

flags.FLAGS(['repro'])
inventory = inventory_csv.Inventory(batch=True)
devices = inventory._ParseDevicesFromCsv(StringIO('device\nrouter_a\nrouter_b\n'))
print(list(devices))

Actual: IndexError: list index out of range at if header_list[-1] == 'flags':.

Expected: ['router_a', 'router_b'], with empty attribute tuples. The parser treats device as the mandatory first column and flags as optional, and constructs a valid zero-field namedtuple after removing the device column. It then indexes the now-empty header list while checking for optional flags.

Guarding that optional-header check would allow minimal inventories without changing ordinary attribute or variable-length flags parsing. Dedicated regressions reproduce the failure for plain and commented/whitespace-padded inventories; header-only, vendor, and flags controls already pass.

Activity

  1. vinsymoyya commented on Nov 14, 2026

    @vinsymoyya
    Author

    Opened #22. The optional flags-header check now handles an empty attribute list, allowing inventories with just the mandatory device column.

    Both affected regressions fail on current master, and the fix passes all 24 inventory tests. Controls cover header-only input, normal attributes, and variable-length flags. Formatting checks pass for the new test and changed source line, with whitespace checks passing. No live device integration was run locally.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions