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_client: avoid TypeError if result["attributes"] is a list #8403

Conversation

thomasbach-dev
Copy link
Contributor

SUMMARY

This fixes a TypeError in the keycloak_client module.

Longer description:

As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we run into:

TypeError: list indices must be integers or slices, not str

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

keycloak_client

ADDITIONAL INFORMATION

Full stack trace (keycloak_client.py got renamed to mdz_keycloak_client.py):

Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1716369175.8611605-165495-177683398669149/AnsiballZ_mdz_keycloak_client.py", line 107, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1716369175.8611605-165495-177683398669149/AnsiballZ_mdz_keycloak_client.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1716369175.8611605-165495-177683398669149/AnsiballZ_mdz_keycloak_client.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible.modules.mdz_keycloak_client', init_globals=dict(_module_fqn='ansible.modules.mdz_keycloak_client', _modlib_path=modlib_path),
  File "/usr/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_mdz_keycloak_client_payload_uw8ct1px/ansible_mdz_keycloak_client_payload.zip/ansible/modules/mdz_keycloak_client.py", line 999, in <module>
  File "/tmp/ansible_mdz_keycloak_client_payload_uw8ct1px/ansible_mdz_keycloak_client_payload.zip/ansible/modules/mdz_keycloak_client.py", line 956, in main
  File "/tmp/ansible_mdz_keycloak_client_payload_uw8ct1px/ansible_mdz_keycloak_client_payload.zip/ansible/modules/mdz_keycloak_client.py", line 779, in sanitize_cr
TypeError: list indices must be integers or slices, not str

@thomasbach-dev thomasbach-dev changed the title fix(keycloak_client): avoid TypeError if attributes is a list keycloak_client: avoid TypeError if result["attributes"] is a list May 22, 2024
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor plugins plugin (any type) small_patch Hopefully easy to review traceback labels May 22, 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 May 22, 2024
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! Please add a changelog fragment. Thanks!

plugins/modules/keycloak_client.py Outdated Show resolved Hide resolved
As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we
run into:

TypeError: list indices must be integers or slices, not str
@thomasbach-dev thomasbach-dev force-pushed the feat/fix-typeerror-in-keycloak-client branch from d9b82cb to 7e641d5 Compare May 23, 2024 11:25
@ansibullbot ansibullbot removed the small_patch Hopefully easy to review label May 23, 2024
@thomasbach-dev
Copy link
Contributor Author

@felixfontein I incorporated your suggestion and added a changelog fragment. Does this look good now?

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label May 26, 2024
@felixfontein felixfontein merged commit 572caea into ansible-collections:main May 26, 2024
132 checks passed
Copy link

patchback bot commented May 26, 2024

Backport to stable-8: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-8/572caeaa39ad3efd6083afafba9fd4fe4c88f9fd/pr-8403

Backported as #8426

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

@felixfontein
Copy link
Collaborator

@thomasbach-dev thanks for fixing this!

patchback bot pushed a commit that referenced this pull request May 26, 2024
…8403)

* fix(keycloak_client): avoid TypeError if attributes is a list

As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we
run into:

TypeError: list indices must be integers or slices, not str

* Update changelog fragment.

---------

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

patchback bot commented May 26, 2024

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/572caeaa39ad3efd6083afafba9fd4fe4c88f9fd/pr-8403

Backported as #8427

🤖 @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 May 26, 2024
…8403)

* fix(keycloak_client): avoid TypeError if attributes is a list

As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we
run into:

TypeError: list indices must be integers or slices, not str

* Update changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 572caea)
felixfontein pushed a commit that referenced this pull request May 26, 2024
…or if `result["attributes"]` is a list (#8426)

keycloak_client: avoid TypeError if `result["attributes"]` is a list (#8403)

* fix(keycloak_client): avoid TypeError if attributes is a list

As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we
run into:

TypeError: list indices must be integers or slices, not str

* Update changelog fragment.

---------

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

Co-authored-by: Thomas Bach <63091663+thomasbach-dev@users.noreply.github.com>
felixfontein pushed a commit that referenced this pull request May 26, 2024
…or if `result["attributes"]` is a list (#8427)

keycloak_client: avoid TypeError if `result["attributes"]` is a list (#8403)

* fix(keycloak_client): avoid TypeError if attributes is a list

As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we
run into:

TypeError: list indices must be integers or slices, not str

* Update changelog fragment.

---------

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

Co-authored-by: Thomas Bach <63091663+thomasbach-dev@users.noreply.github.com>
@thomasbach-dev thomasbach-dev deleted the feat/fix-typeerror-in-keycloak-client branch June 3, 2024 11:54
Massl123 pushed a commit to Massl123/community.general that referenced this pull request Feb 7, 2025
…nsible-collections#8403)

* fix(keycloak_client): avoid TypeError if attributes is a list

As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we
run into:

TypeError: list indices must be integers or slices, not str

* Update changelog fragment.

---------

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 new_contributor Help guide this first time contributor plugins plugin (any type) traceback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants