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

[DRAFT] postgresql_info: handle encoding #805

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions plugins/modules/postgresql_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,25 @@ def get_pub_info(self):

return publications

def __decode_col_name_from_bin_to_utf8(self, returned_columns):
# When column names are returned as bytes we need
# to decode them to UTF-8 before using them in queries
# https://github.com/ansible-collections/community.postgresql/issues/790
# https://github.com/ansible-collections/community.postgresql/pull/791
for row in returned_columns:
if isinstance(row["column_name"], bytes):
row["column_name"] = row["column_name"].decode('utf-8')

return returned_columns

def get_subscr_info(self):
"""Get subscription statistics."""
columns_sub_table = ("SELECT column_name "
"FROM information_schema.columns "
"WHERE table_schema = 'pg_catalog' "
"AND table_name = 'pg_subscription'")
columns_result = self.__exec_sql(columns_sub_table)
columns_result = self.__decode_col_name_from_bin_to_utf8(columns_result)
columns = ", ".join(["s.%s" % column["column_name"] for column in columns_result])

query = ("SELECT %s, r.rolname AS ownername, d.datname AS dbname "
Expand Down