From 7e2dbdd4b3624f590a88541e376928d3f253dd69 Mon Sep 17 00:00:00 2001 From: Eldinnie Date: Wed, 13 Feb 2019 23:28:48 +0100 Subject: [PATCH] Fix #1297 (#1342) * Fix #1297 This makes a deepcopy of the user_data and chat_data dict as suggested by @Bibo-Joshi * Fix dictpersistence aswel. --- telegram/ext/dictpersistence.py | 6 ++++-- telegram/ext/picklepersistence.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/telegram/ext/dictpersistence.py b/telegram/ext/dictpersistence.py index 28ca47273..7013fd44b 100644 --- a/telegram/ext/dictpersistence.py +++ b/telegram/ext/dictpersistence.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. """This module contains the DictPersistence class.""" +from copy import deepcopy + from telegram.utils.helpers import decode_user_chat_data_from_json,\ decode_conversations_from_json, enocde_conversations_to_json @@ -129,7 +131,7 @@ class DictPersistence(BasePersistence): pass else: self._user_data = defaultdict(dict) - return self.user_data.copy() + return deepcopy(self.user_data) def get_chat_data(self): """Returns the chat_data created from the ``chat_data_json`` or an empty defaultdict. @@ -141,7 +143,7 @@ class DictPersistence(BasePersistence): pass else: self._chat_data = defaultdict(dict) - return self.chat_data.copy() + return deepcopy(self.chat_data) def get_conversations(self, name): """Returns the conversations created from the ``conversations_json`` or an empty diff --git a/telegram/ext/picklepersistence.py b/telegram/ext/picklepersistence.py index ed3c06cf9..b6472f70e 100644 --- a/telegram/ext/picklepersistence.py +++ b/telegram/ext/picklepersistence.py @@ -19,6 +19,7 @@ """This module contains the PicklePersistence class.""" import pickle from collections import defaultdict +from copy import deepcopy from telegram.ext import BasePersistence @@ -122,7 +123,7 @@ class PicklePersistence(BasePersistence): self.user_data = data else: self.load_singlefile() - return self.user_data.copy() + return deepcopy(self.user_data) def get_chat_data(self): """Returns the chat_data from the pickle file if it exsists or an empty defaultdict. @@ -142,7 +143,7 @@ class PicklePersistence(BasePersistence): self.chat_data = data else: self.load_singlefile() - return self.chat_data.copy() + return deepcopy(self.chat_data) def get_conversations(self, name): """Returns the conversations from the pickle file if it exsists or an empty defaultdict.