* Fix #1297

This makes a deepcopy of the user_data and chat_data dict as suggested by @Bibo-Joshi

* Fix dictpersistence aswel.
This commit is contained in:
Eldinnie 2019-02-13 23:28:48 +01:00 committed by Jasmin Bom
parent da342af7ed
commit 7e2dbdd4b3
2 changed files with 7 additions and 4 deletions

View file

@ -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

View file

@ -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.