Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keycloak_user_federation: fix key error when removing mappers in update #8762

Conversation

fgruenbauer
Copy link
Contributor

@fgruenbauer fgruenbauer commented Aug 14, 2024

SUMMARY

The module throws a key error in update code path if there is a new mapper specified in the module arguments.

The desired mapper list

if not before_mapper['id'] in [x['id'] for x in desired_mappers]:
contains the existing mappers we want to keep, the existing ones that will be updated and the mappers that will be newly created. Since we want to remove unwanted existing mappers, we can exclude the new mappers that dont have an id yet when checking if we want to keep an existing mapper.

Fixes key error when updating and a new mapper is specified in the module arguments.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

keycloak_user_federation

ADDITIONAL INFORMATION

Add a new mapper to the module arguments before running a user federation update.

The full traceback is:
Traceback (most recent call last):
  File "/home/gruenbauer/.ansible/tmp/ansible-tmp-1723626012.332673-85886-4585327035734/AnsiballZ_keycloak_user_federation.py", line 107, in <module>
    _ansiballz_main()
  File "/home/gruenbauer/.ansible/tmp/ansible-tmp-1723626012.332673-85886-4585327035734/AnsiballZ_keycloak_user_federation.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/gruenbauer/.ansible/tmp/ansible-tmp-1723626012.332673-85886-4585327035734/AnsiballZ_keycloak_user_federation.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.keycloak_user_federation', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.keycloak_user_federation', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/ansible_community.general.keycloak_user_federation_payload_y_yq1nli/ansible_community.general.keycloak_user_federation_payload.zip/ansible_collections/community/general/plugins/modules/keycloak_user_federation.py", line 1052, in <module>
  File "/tmp/ansible_community.general.keycloak_user_federation_payload_y_yq1nli/ansible_community.general.keycloak_user_federation_payload.zip/ansible_collections/community/general/plugins/modules/keycloak_user_federation.py", line 1007, in main
KeyError: 'id'
fatal: [kc1]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/gruenbauer/.ansible/tmp/ansible-tmp-1723626012.332673-85886-4585327035734/AnsiballZ_keycloak_user_federation.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/gruenbauer/.ansible/tmp/ansible-tmp-1723626012.332673-85886-4585327035734/AnsiballZ_keycloak_user_federation.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/gruenbauer/.ansible/tmp/ansible-tmp-1723626012.332673-85886-4585327035734/AnsiballZ_keycloak_user_federation.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.keycloak_user_federation', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.keycloak_user_federation', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_community.general.keycloak_user_federation_payload_y_yq1nli/ansible_community.general.keycloak_user_federation_payload.zip/ansible_collections/community/general/plugins/modules/keycloak_user_federation.py\", line 1052, in <module>\n  File \"/tmp/ansible_community.general.keycloak_user_federation_payload_y_yq1nli/ansible_community.general.keycloak_user_federation_payload.zip/ansible_collections/community/general/plugins/modules/keycloak_user_federation.py\", line 1007, in main\nKeyError: 'id'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added WIP Work in progress bug This issue/PR relates to a bug module module needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI plugins plugin (any type) small_patch Hopefully easy to review traceback labels Aug 14, 2024
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch labels Aug 14, 2024
@ansibullbot ansibullbot removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI small_patch Hopefully easy to review labels Aug 14, 2024
@canon-cmre-benoit-lecardonnel

Hi @fgruenbauer, thanks for the PR - It solves the KeyError: 'id' issue mentioned on #8695 :)

…or-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>
@fgruenbauer fgruenbauer marked this pull request as ready for review August 19, 2024 09:26
@ansibullbot ansibullbot removed the WIP Work in progress label Aug 19, 2024
@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Aug 20, 2024
@felixfontein felixfontein merged commit b79ac4f into ansible-collections:main Aug 20, 2024
147 checks passed
Copy link

patchback bot commented Aug 20, 2024

Backport to stable-8: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-8/b79ac4f0ac3225da70fa52d2c6df2734457813e4/pr-8762

Backported as #8780

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Aug 20, 2024
…te (#8762)

* remove new mappers without an id from list comprehension

* add changelog fragment

* Update changelogs/fragments/8762-keycloac_user_federation-fix-key-error-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b79ac4f)
Copy link

patchback bot commented Aug 20, 2024

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/b79ac4f0ac3225da70fa52d2c6df2734457813e4/pr-8762

Backported as #8781

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Aug 20, 2024
…te (#8762)

* remove new mappers without an id from list comprehension

* add changelog fragment

* Update changelogs/fragments/8762-keycloac_user_federation-fix-key-error-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b79ac4f)
@felixfontein
Copy link
Collaborator

@fgruenbauer thanks for fixing this!
@canon-cmre-benoit-lecardonnel thanks for testing!

felixfontein pushed a commit that referenced this pull request Aug 20, 2024
…key error when removing mappers in update (#8780)

keycloak_user_federation: fix key error when removing mappers in update (#8762)

* remove new mappers without an id from list comprehension

* add changelog fragment

* Update changelogs/fragments/8762-keycloac_user_federation-fix-key-error-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b79ac4f)

Co-authored-by: fgruenbauer <gruenbauer@b1-systems.de>
felixfontein pushed a commit that referenced this pull request Aug 20, 2024
…key error when removing mappers in update (#8781)

keycloak_user_federation: fix key error when removing mappers in update (#8762)

* remove new mappers without an id from list comprehension

* add changelog fragment

* Update changelogs/fragments/8762-keycloac_user_federation-fix-key-error-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b79ac4f)

Co-authored-by: fgruenbauer <gruenbauer@b1-systems.de>
fgruenbauer added a commit to fgruenbauer/community.general that referenced this pull request Aug 20, 2024
…te (ansible-collections#8762)

* remove new mappers without an id from list comprehension

* add changelog fragment

* Update changelogs/fragments/8762-keycloac_user_federation-fix-key-error-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
aioue pushed a commit to aioue/community.general that referenced this pull request Oct 1, 2024
…te (ansible-collections#8762)

* remove new mappers without an id from list comprehension

* add changelog fragment

* Update changelogs/fragments/8762-keycloac_user_federation-fix-key-error-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
TobiasZeuch181 pushed a commit to TobiasZeuch181/zypper_repository_add_list that referenced this pull request Oct 2, 2024
…te (ansible-collections#8762)

* remove new mappers without an id from list comprehension

* add changelog fragment

* Update changelogs/fragments/8762-keycloac_user_federation-fix-key-error-when-updating.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch bug This issue/PR relates to a bug module module plugins plugin (any type) traceback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants