Skip to content

Fix KeyError: 'id' in io filters _normalize on name-only choice lists#1014

Merged
SteveMcGrath merged 1 commit into
tenable:mainfrom
arpitjain099:chore/filters-normalize-keyerror
Jun 29, 2026
Merged

Fix KeyError: 'id' in io filters _normalize on name-only choice lists#1014
SteveMcGrath merged 1 commit into
tenable:mainfrom
arpitjain099:chore/filters-normalize-keyerror

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

Calling tio.assets.bulk_delete() blows up with KeyError: 'id' on any tenant that still has Target groups. The cause is in io.filters._normalize: when a choice list item only carries a name (the shape the target_group filter returns), the code falls back to assuming an id key and indexes into something that isn't there. This now picks the first key that actually exists out of value, id, then name, and skips list items that don't have it, so a name-only list resolves to its names instead of throwing.

Fixes #1009

I added a regression test (test_normalize_name_only_choices) that feeds _normalize the exact target_group shape from the issue. It fails with KeyError: 'id' on current main and passes with this change. pytest tests/io/test_filters.py tests/io/test_assets.py stays green (31 passed) and ruff is clean on the changed file. Tested on Python 3.12.

Type of change:

  • Bug fix (non-breaking change which fixes an issue)

Some filter choice lists (e.g. the target_group filter) carry items with
only a 'name' key, not 'value' or 'id'. _normalize assumed 'id' as the
fallback key and raised KeyError: 'id', which broke tio.assets.bulk_delete()
on tenants that still have target groups. Pick the first key that actually
exists ('value', 'id', then 'name') and skip items missing it.

Fixes tenable#1009

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099 arpitjain099 requested a review from a team as a code owner June 29, 2026 02:54
@SteveMcGrath SteveMcGrath merged commit bd0a19a into tenable:main Jun 29, 2026
7 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.

Call to tio.assets.bulk_delete() leads to KeyError: 'id' on Target groups

2 participants