From c88a40d3e3229cccfce4bad6b2313440ced5f217 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:19:35 +0000 Subject: [PATCH] [PR #8557/6e0142fe backport][stable-9] bitwarden: Fix KeyError in search_field (#8549) (#8563) bitwarden: Fix KeyError in search_field (#8549) (#8557) * bitwarden: Fix KeyError in search_field (#8549) * Update changelogs/fragments/8557-fix-bug-with-bitwarden.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 6e0142fe3aa7c0e8087a51e352c931dc7ddcf7f0) Co-authored-by: Kai --- changelogs/fragments/8557-fix-bug-with-bitwarden.yml | 2 ++ plugins/lookup/bitwarden.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/8557-fix-bug-with-bitwarden.yml diff --git a/changelogs/fragments/8557-fix-bug-with-bitwarden.yml b/changelogs/fragments/8557-fix-bug-with-bitwarden.yml new file mode 100644 index 0000000000..cf41ae209f --- /dev/null +++ b/changelogs/fragments/8557-fix-bug-with-bitwarden.yml @@ -0,0 +1,2 @@ +bugfixes: + - "bitwarden lookup plugin - fix ``KeyError`` in ``search_field`` (https://github.com/ansible-collections/community.general/issues/8549, https://github.com/ansible-collections/community.general/pull/8557)." \ No newline at end of file diff --git a/plugins/lookup/bitwarden.py b/plugins/lookup/bitwarden.py index 7584cd98a6..5e31cc6f89 100644 --- a/plugins/lookup/bitwarden.py +++ b/plugins/lookup/bitwarden.py @@ -174,8 +174,9 @@ class Bitwarden(object): else: initial_matches = [initial_matches] - # Filter to only include results from the right field. - return [item for item in initial_matches if not search_value or item[search_field] == search_value] + # Filter to only include results from the right field, if a search is requested by value or field + return [item for item in initial_matches + if not search_value or not search_field or item.get(search_field) == search_value] def get_field(self, field, search_value, search_field="name", collection_id=None, organization_id=None): """Return a list of the specified field for records whose search_field match search_value