1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

postgresql_privs: fix the module mistakes a procedure for a function (#996)

* postgresql_privs: fix the module mistakes a procedure for a function

* add changelog fragment

* fix
This commit is contained in:
Andrew Klychkov 2020-09-29 21:27:30 +03:00 committed by GitHub
parent 104f6a3e96
commit 220051768b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 5 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- postgresql_privs - fix the module mistakes a procedure for a function (https://github.com/ansible-collections/community.general/issues/994).

View file

@ -514,6 +514,7 @@ class Connection(object):
self.connection = psycopg2.connect(**kw)
self.cursor = self.connection.cursor()
self.pg_version = self.connection.server_version
def commit(self):
self.connection.commit()
@ -561,10 +562,15 @@ class Connection(object):
def get_all_functions_in_schema(self, schema):
if not self.schema_exists(schema):
raise Error('Schema "%s" does not exist.' % schema)
query = """SELECT p.proname, oidvectortypes(p.proargtypes)
FROM pg_catalog.pg_proc p
JOIN pg_namespace n ON n.oid = p.pronamespace
WHERE nspname = %s"""
query = ("SELECT p.proname, oidvectortypes(p.proargtypes) "
"FROM pg_catalog.pg_proc p "
"JOIN pg_namespace n ON n.oid = p.pronamespace "
"WHERE nspname = %s")
if self.pg_version >= 110000:
query += " and p.prokind = 'f'"
self.cursor.execute(query, (schema,))
return ["%s(%s)" % (t[0], t[1]) for t in self.cursor.fetchall()]
@ -1120,7 +1126,7 @@ def main():
except psycopg2.Error as e:
conn.rollback()
module.fail_json(msg=to_native(e.message))
module.fail_json(msg=to_native(e))
if module.check_mode or not changed:
conn.rollback()

View file

@ -653,6 +653,35 @@
login_user: "{{ db_user3 }}"
login_password: password
# Issue https://github.com/ansible-collections/community.general/issues/994
- name: Create a procedure for tests
postgresql_query:
query: "CREATE PROCEDURE mock_procedure() LANGUAGE SQL AS $$ SELECT 1; $$;"
db: "{{ db_name }}"
login_user: "{{ db_user3 }}"
login_password: password
when: postgres_version_resp.stdout is version('11', '>=')
# Issue https://github.com/ansible-collections/community.general/issues/994
- name: Try to run module against a procedure, not function
postgresql_privs:
type: function
state: present
privs: ALL
roles: "{{ db_user2 }}"
objs: ALL_IN_SCHEMA
schema: public
db: "{{ db_name }}"
login_user: "{{ db_user3 }}"
login_password: password
register: result
when: postgres_version_resp.stdout is version('11', '>=')
- assert:
that:
- result is not changed
when: postgres_version_resp.stdout is version('11', '>=')
#################################################
# Test ALL_IN_SCHEMA for 'partioned tables type #
#################################################