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 b235d96c6a9..ba8324dde68 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_privs.py +++ b/lib/ansible/modules/database/postgresql/postgresql_privs.py @@ -780,8 +780,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