From b476eff9dbb2c6702d7bfa699cbf3e096947a3e2 Mon Sep 17 00:00:00 2001 From: David Delassus Date: Fri, 28 Jul 2023 02:06:54 +0200 Subject: [PATCH] Fix bug in nb_lookup if api_filter contains multiple `id` In the `nb_lookup` plugin, if we provide an `api_filter` containing the `id` field, it will use `.get()` instead of `.filter()`, thus returning the item instead of a list. See PR #376 for more information. This is fine if you supply only one id. But let's say you want to get a list of items by ids? For example: `id=1 id=5` I would expect to get a list of 2 items. But at the moment, it will return the first item only. This change adds a simple check to see if we're supplying multiple ids. --- plugins/lookup/nb_lookup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lookup/nb_lookup.py b/plugins/lookup/nb_lookup.py index d015bc704..84b883837 100644 --- a/plugins/lookup/nb_lookup.py +++ b/plugins/lookup/nb_lookup.py @@ -439,7 +439,7 @@ def run(self, terms, variables=None, **kwargs): if netbox_api_filter: filter = build_filters(netbox_api_filter) - if "id" in filter: + if "id" in filter and len(filter["id"]) == 1: Display().vvvv( "Filter is: %s and includes id, will use .get instead of .filter" % (filter)