From d9ab39b03f2370d306e2447f86a2a1116478331e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6hme?= Date: Fri, 24 Mar 2017 13:48:11 +0100 Subject: [PATCH] Fix loading of additional_data column from log database Currently, the additional_data column is not correctly loaded from the log database in the logger module's methods get_last_conversation_lines and get_conversation_for_date. While the JSON data in the column is parsed, the parsed value is not saved, because the code assumes that changes to a loop variable are reflected in the list that is iterated over. Instead, the unparsed JSON string is returned. Fix this by building a separate list with the JSON string replaced by the parsed JSON object. --- src/common/logger.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index 1f6db311c..cb480b6c5 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -609,13 +609,16 @@ class Logger: restore_how_many_rows, pending_how_many), jid_tuple) results = self.cur.fetchall() + messages = [] for entry in results: - entry = list(entry) - entry[4] = json.loads(entry[4]) + additional_data = json.loads(entry[4]) + parsed_entry = entry[:4] + (additional_data, ) + entry[5:] + messages.append(parsed_entry) except sqlite.DatabaseError: raise exceptions.DatabaseMalformed - results.reverse() - return results + + messages.reverse() + return messages def get_unix_time_from_date(self, year, month, day): # year (fe 2005), month (fe 11), day (fe 25) @@ -655,10 +658,13 @@ class Logger: ''' % (where_sql, start_of_day, last_second_of_day), jid_tuple) results = self.cur.fetchall() + messages = [] for entry in results: - entry = list(entry) - entry[6] = json.loads(entry[6]) - return results + additional_data = json.loads(entry[6]) + parsed_entry = entry[:6] + (additional_data, ) + entry[7:] + messages.append(parsed_entry) + + return messages def get_search_results_for_query(self, jid, query, account, year=False, month=False, day=False):