Fix KeyError: 'id' in io filters _normalize on name-only choice lists#1014
Merged
SteveMcGrath merged 1 commit intoJun 29, 2026
Merged
Conversation
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>
SteveMcGrath
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling
tio.assets.bulk_delete()blows up withKeyError: 'id'on any tenant that still has Target groups. The cause is inio.filters._normalize: when a choice list item only carries aname(the shape thetarget_groupfilter returns), the code falls back to assuming anidkey 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_normalizethe exacttarget_groupshape from the issue. It fails withKeyError: 'id'on current main and passes with this change.pytest tests/io/test_filters.py tests/io/test_assets.pystays green (31 passed) and ruff is clean on the changed file. Tested on Python 3.12.Type of change: