-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
Hey! Your de_json() methods mess with actual data in the request object.
Here:
def de_json(data):
"""
Args:
data (dict):
Returns:
telegram.Update:
"""
if not data:
return None
data['message'] = Message.de_json(data.get('message'))
data['edited_message'] = Message.de_json(data.get('edited_message'))
data['inline_query'] = InlineQuery.de_json(data.get('inline_query'))
data['chosen_inline_result'] = ChosenInlineResult.de_json(data.get('chosen_inline_result'))
data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'))
return Update(**data)
You see, you change data dictionary, and since it's one of python's mutable data structures, it changes too. Here is an example:
print('REQUEST', request.get_json(force=True))
update = telegram.update.Update.de_json(request.get_json(force=True))
print('REQUEST', request.get_json(force=True))
the result is:
2016-07-22T12:52:33.626071+00:00 app[web.1]: REQUEST {'update_id': 938970460, 'inline_query': {'query': '567', 'offset': '', 'from': {'first_name': 'Mike', 'username': 'zuldare', 'last_name': 'Salnikov', 'id': 97081120}, 'id': '416960237449083811'}}
2016-07-22T12:52:33.626213+00:00 app[web.1]: REQUEST {'inline_query': <telegram.inlinequery.InlineQuery object at 0x7f84fecdcf60>, 'message': None, 'update_id': 938970460, 'chosen_inline_result': None, 'callback_query': None, 'edited_message': None}
which should be not that big a deal in most cases, but in some could be very bad