From 2ae41fa83f44aefce38cd845e377dcdd73b9f32b Mon Sep 17 00:00:00 2001 From: fgruenbauer Date: Mon, 9 Sep 2024 14:05:48 +0200 Subject: [PATCH] keycloak_user_federation: get the before mappers from `before_comp` to fix `UnboundLocalError` (#8831) * fix: get the before mappers from `before_comp` * add changelog fragment * Adjust changelog fragment. --------- Co-authored-by: Felix Fontein --- .../fragments/8831-fix-error-when-mapper-id-is-provided.yml | 2 ++ plugins/modules/keycloak_user_federation.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/8831-fix-error-when-mapper-id-is-provided.yml diff --git a/changelogs/fragments/8831-fix-error-when-mapper-id-is-provided.yml b/changelogs/fragments/8831-fix-error-when-mapper-id-is-provided.yml new file mode 100644 index 0000000000..63ac352057 --- /dev/null +++ b/changelogs/fragments/8831-fix-error-when-mapper-id-is-provided.yml @@ -0,0 +1,2 @@ +bugfixes: + - keycloak_user_federation - fix the ``UnboundLocalError`` that occurs when an ID is provided for a user federation mapper (https://github.com/ansible-collections/community.general/pull/8831). \ No newline at end of file diff --git a/plugins/modules/keycloak_user_federation.py b/plugins/modules/keycloak_user_federation.py index f80d694e07..6034aa8b84 100644 --- a/plugins/modules/keycloak_user_federation.py +++ b/plugins/modules/keycloak_user_federation.py @@ -907,7 +907,7 @@ def main(): if cid is None: old_mapper = {} elif change.get('id') is not None: - old_mapper = next((before_mapper for before_mapper in before_mapper.get('mappers', []) if before_mapper["id"] == change['id']), None) + old_mapper = next((before_mapper for before_mapper in before_comp.get('mappers', []) if before_mapper["id"] == change['id']), None) if old_mapper is None: old_mapper = {} else: