Skip to content

Weird KeyError with ConversationHandler and CallbackQueryHandler #373

@jsmnbom

Description

@jsmnbom

Steps to reproduce

  1. Run code example below:
import logging
import os
import sys

from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import (Updater, ConversationHandler, CallbackQueryHandler, CommandHandler)
from telegram.ext.dispatcher import run_async


def error(bot, update, err):
    logging.warning('Update "%s" caused error "%s"' % (update, err))


def start(bot, update):
    buttons = [[InlineKeyboardButton(text='Click me!', callback_data='Something')]]
    bot.send_message(chat_id=update.message.chat.id,
                     text='Click the button below and look at log.',
                     reply_markup=InlineKeyboardMarkup(buttons))


# If you add a @run_async here the error changes to be on line 216 of ConversationHandler
def test(bot, update):
    # Doesn't matter what's in this func
    return ConversationHandler.END


logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

token = os.getenv('TEST-TOKEN')
if not token:
    logging.critical('NO TOKEN FOUND!')
    sys.exit()

updater = Updater(token)

dp = updater.dispatcher

test_handler = ConversationHandler(
    entry_points=[
        CallbackQueryHandler(test)
    ],
    states={},
    fallbacks=[]
)

start_handler = CommandHandler('start', start)

dp.add_handler(test_handler)
dp.add_handler(start_handler)

dp.add_error_handler(error)

updater.start_polling()

updater.idle()
  1. Send a /start to bot
  2. Click the Click me inline button

Expected behaviour

No error in log.

Actual behaviour

A KeyError is shown in log (see logs below).
Note: It doesn't actually crash.

Configuration

Operating System:
Windows 10 Education

Version of Python, python-telegram-bot & dependencies:
$ python -m telegram
python-telegram-bot 5.0.0 (newest master branch)
urllib3 1.16
certifi 2016.08.02
future 0.15.2
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]

Logs

https://gist.github.com/bomjacob/d9ae92f414a5c796eb86ac36b78b56d0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions