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

extension version without decimal causes postgresql_info exception #137

Closed
phemmer opened this issue Sep 1, 2021 · 7 comments · Fixed by #138
Closed

extension version without decimal causes postgresql_info exception #137

phemmer opened this issue Sep 1, 2021 · 7 comments · Fixed by #138
Labels
help wanted Extra attention is needed

Comments

@phemmer
Copy link

phemmer commented Sep 1, 2021

SUMMARY

When an extension is installed that doesn't have a . in the version, the postgresql_info module throws an exception.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

postgresql_info

ANSIBLE VERSION
ansible 2.10.11
  config file = None
  configured module search path = ['/home/phemmer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/phemmer/.local/lib/python3.9/site-packages/ansible
  executable location = /home/phemmer/.local/bin/ansible
  python version = 3.9.5 (default, May 14 2021, 00:00:00) [GCC 11.1.1 20210428 (Red Hat 11.1.1-1)]
COLLECTION VERSION
# /home/phemmer/.local/lib/python3.9/site-packages/ansible_collections
Collection           Version
-------------------- -------
community.postgresql 1.1.1  
CONFIGURATION
OS / ENVIRONMENT

Debian 10/Buster
PostgreSQL 13

STEPS TO REPRODUCE
  1. Install an extension without a . in the version, for example pguint.
# psql mydb
mydb=> select * from pg_available_extensions where name='uint';
 name | default_version | installed_version |        comment         
------+-----------------+-------------------+------------------------
 uint | 0               |                   | unsigned integer types
(1 row)

mydb=> create extension uint;
CREATE EXTENSION
  1. use postgresql_info.
ansible myhost -m postgresql_info
EXPECTED RESULTS

Works

ACTUAL RESULTS
# ansible myhost -m postgresql_info
The full traceback is:
Traceback (most recent call last):
  File "master:/home/phemmer/git/ht/edge/ansible/ht/mitogen/ansible_mitogen/runner.py", line 975, in _run
    self._run_code(code, mod)
  File "master:/home/phemmer/git/ht/edge/ansible/ht/mitogen/ansible_mitogen/runner.py", line 939, in _run_code
    exec(code, vars(mod))
  File "master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py", line 1030, in <module>
  File "master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py", line 1026, in main
  File "master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py", line 617, in collect
  File "master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py", line 973, in get_db_info
  File "master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py", line 734, in get_ext_info
IndexError: list index out of range
myhost | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"master:/home/phemmer/git/ht/edge/ansible/ht/mitogen/ansible_mitogen/runner.py\", line 975, in _run\n    self._run_code(code, mod)\n  File \"master:/home/phemmer/git/ht/edge/ansible/ht/mitogen/ansible_mitogen/runner.py\", line 939, in _run_code\n    exec(code, vars(mod))\n  File \"master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py\", line 1030, in <module>\n  File \"master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py\", line 1026, in main\n  File \"master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py\", line 617, in collect\n  File \"master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py\", line 973, in get_db_info\n  File \"master:/home/phemmer/.local/lib/python3.9/site-packages/ansible_collections/community/general/plugins/modules/postgresql_info.py\", line 734, in get_ext_info\nIndexError: list index out of range\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
@phemmer phemmer changed the title '0' version extension causes postgresql_info exception extension version without decimal causes postgresql_info exception Sep 1, 2021
@phemmer
Copy link
Author

phemmer commented Sep 1, 2021

This looks like it'd be trivial to fix, however there are several approaches, none of them good.

Ultimately the problem is that postgresql_info is assuming that all extension versions follow a convention containing major and minor components separated by decimal (.). This is not the case. In addition to this example which only has a single component, other plugins may have 3 or more components when split.

As such, my proposal would be either:

  1. Don't split the version, leave it as a string.
  2. Split and return as an array.

I think # 1 is the safer option. If people really need it split, they can split it themselves.
However both options are breaking changes.

@Andersson007
Copy link
Collaborator

@phemmer hello, thank you for reporting this and welcome to the project!

I'll take a closer look tomorrow.

Quick thoughts:

  1. we can check the length after splitting and handle this case properly, e.g. put None to minor part.
  2. in any case we can add a parameter called raw to return versions as they are. It wouldn't be a breaking change

If you want to fix this, we have a quick start guide to help newcomers, here it is https://github.com/ansible/community-docs/blob/main/create_pr_quick_start_guide.rst. What do you think? Feel free to raise a PR

@Andersson007
Copy link
Collaborator

@phemmer after evaluating things, could you please put it in here explicitly if you have time to fix this or not (to avoid working in parallel). Thank you:)

@phemmer
Copy link
Author

phemmer commented Sep 2, 2021

Sorry for delay, I doubt I'll have time to fix and submit a PR. But will let you know if that changes.

@Andersson007
Copy link
Collaborator

@phemmer no problem! Thanks for the feedback. OK, if anyone wants, feel free to pick it up (put your intention explicitly in here).

@Andersson007 Andersson007 added easyfix help wanted Extra attention is needed labels Sep 3, 2021
@Andersson007
Copy link
Collaborator

I'm looking (btw it's not as easy as i thought)

@Andersson007
Copy link
Collaborator

#138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants