mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-10 12:02:39 +01:00
* 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:
parent
da342af7ed
commit
7e2dbdd4b3
2 changed files with 7 additions and 4 deletions
|
@ -17,6 +17,8 @@
|
||||||
# You should have received a copy of the GNU Lesser Public License
|
# You should have received a copy of the GNU Lesser Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
"""This module contains the DictPersistence class."""
|
"""This module contains the DictPersistence class."""
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from telegram.utils.helpers import decode_user_chat_data_from_json,\
|
from telegram.utils.helpers import decode_user_chat_data_from_json,\
|
||||||
decode_conversations_from_json, enocde_conversations_to_json
|
decode_conversations_from_json, enocde_conversations_to_json
|
||||||
|
|
||||||
|
@ -129,7 +131,7 @@ class DictPersistence(BasePersistence):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self._user_data = defaultdict(dict)
|
self._user_data = defaultdict(dict)
|
||||||
return self.user_data.copy()
|
return deepcopy(self.user_data)
|
||||||
|
|
||||||
def get_chat_data(self):
|
def get_chat_data(self):
|
||||||
"""Returns the chat_data created from the ``chat_data_json`` or an empty defaultdict.
|
"""Returns the chat_data created from the ``chat_data_json`` or an empty defaultdict.
|
||||||
|
@ -141,7 +143,7 @@ class DictPersistence(BasePersistence):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self._chat_data = defaultdict(dict)
|
self._chat_data = defaultdict(dict)
|
||||||
return self.chat_data.copy()
|
return deepcopy(self.chat_data)
|
||||||
|
|
||||||
def get_conversations(self, name):
|
def get_conversations(self, name):
|
||||||
"""Returns the conversations created from the ``conversations_json`` or an empty
|
"""Returns the conversations created from the ``conversations_json`` or an empty
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"""This module contains the PicklePersistence class."""
|
"""This module contains the PicklePersistence class."""
|
||||||
import pickle
|
import pickle
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from telegram.ext import BasePersistence
|
from telegram.ext import BasePersistence
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ class PicklePersistence(BasePersistence):
|
||||||
self.user_data = data
|
self.user_data = data
|
||||||
else:
|
else:
|
||||||
self.load_singlefile()
|
self.load_singlefile()
|
||||||
return self.user_data.copy()
|
return deepcopy(self.user_data)
|
||||||
|
|
||||||
def get_chat_data(self):
|
def get_chat_data(self):
|
||||||
"""Returns the chat_data from the pickle file if it exsists or an empty defaultdict.
|
"""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
|
self.chat_data = data
|
||||||
else:
|
else:
|
||||||
self.load_singlefile()
|
self.load_singlefile()
|
||||||
return self.chat_data.copy()
|
return deepcopy(self.chat_data)
|
||||||
|
|
||||||
def get_conversations(self, name):
|
def get_conversations(self, name):
|
||||||
"""Returns the conversations from the pickle file if it exsists or an empty defaultdict.
|
"""Returns the conversations from the pickle file if it exsists or an empty defaultdict.
|
||||||
|
|
Loading…
Reference in a new issue