From 13031109aa40a98ad1a0bd95f142f2e2cad8833c Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Tue, 17 Dec 2019 16:53:51 +0300 Subject: [PATCH] Bugfix of 65761: postgresql_privs fail after it's updated to 2.9.2 (#65903) * Bugfix of 65761: postgresql_privs fail after it's updated to 2.9.2 * add changelog (cherry picked from commit 9b85a51c64a687f8db4a9bfe3fea0f62f5f65af2) --- ...ostgresql_privs_sort_lists_with_none_elements.yml | 2 ++ .../modules/database/postgresql/postgresql_privs.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/65903-postgresql_privs_sort_lists_with_none_elements.yml diff --git a/changelogs/fragments/65903-postgresql_privs_sort_lists_with_none_elements.yml b/changelogs/fragments/65903-postgresql_privs_sort_lists_with_none_elements.yml new file mode 100644 index 00000000000..2a74e389809 --- /dev/null +++ b/changelogs/fragments/65903-postgresql_privs_sort_lists_with_none_elements.yml @@ -0,0 +1,2 @@ +bugfixes: +- postgresql_privs - fix sorting lists with None elements for python3 (https://github.com/ansible/ansible/issues/65761). diff --git a/lib/ansible/modules/database/postgresql/postgresql_privs.py b/lib/ansible/modules/database/postgresql/postgresql_privs.py index 65081d4f47e..96ba006a13a 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_privs.py +++ b/lib/ansible/modules/database/postgresql/postgresql_privs.py @@ -749,8 +749,16 @@ class Connection(object): executed_queries.append(query) self.cursor.execute(query) status_after = get_status(objs) - status_before.sort() - status_after.sort() + + def nonesorted(e): + # For python 3+ that can fail trying + # to compare NoneType elements by sort method. + if e is None: + return '' + return e + + status_before.sort(key=nonesorted) + status_after.sort(key=nonesorted) return status_before != status_after