Skip to content

AttributeError while handling through AIORateLimiter #4831

Closed
@Natan7217

Description

@Natan7217

Steps to Reproduce

  1. Used AIOlimiter and returned in AIOlimiter.process_request None
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, AIORateLimiter
from telegram import Update


async def send_sth(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
    return await ctx.bot.send_message(
        chat_id=update.effective_chat.id, reply_to_message_id=update.message.id, parse_mode="HTML",
        text="sth")


class CustomLimiter(AIORateLimiter):
    def __init__(self):
        super().__init__()

    async def process_request(self, callback, args, kwargs, endpoint: str, data, rate_limit_args):
        # <some logic here to process if not RateLimited>
        if endpoint not in ['getMe', 'getUpdates', "deleteWebhook"]:
            return  # but the AttributeError doesn't happen if return {"from": None, 'date': 0, 'message_id': 0}
        return await callback(*args, **kwargs)


if __name__ == "__main__":
    rate_limiter = CustomLimiter()
    application = ApplicationBuilder().token("<API_TOKEN>").read_timeout(30).get_updates_read_timeout(60) \
        .rate_limiter(rate_limiter).build()
    sth_handler = CommandHandler("start", send_sth)
    application.add_handler(sth_handler)
    application.run_polling(timeout=60)

Expected behaviour

https://github.com/python-telegram-bot/python-telegram-bot/blob/master/src/telegram/ext/_baseratelimiter.py
In the line 140 it tells that can be returned None and all will work ok

Actual behaviour

To make a long story short just AttributeError

Operating System

Windows 10 NT

Version of Python, python-telegram-bot & dependencies

python3.10
python-telegram-bot 22.1

Relevant log output

Output:

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "....\lib\site-packages\telegram\ext\_application.py", line 1878, in process_error
    await callback(update, context)
  File "....\sth.py", line 1215, in error_handler
    return await ctx.bot.send_message(........),
  File "....\lib\site-packages\telegram\ext\_extbot.py", line 2712, in send_document
    return await super().send_document(
  File "...\lib\site-packages\telegram\_bot.py", line 1804, in send_document
    return await self._send_message(
  File "....\lib\site-packages\telegram\ext\_extbot.py", line 629, in _send_message
    result = await super()._send_message(
  File "....\lib\site-packages\telegram\_bot.py", line 822, in _send_message
    return Message.de_json(result, self)
  File "....\lib\site-packages\telegram\_message.py", line 1306, in de_json
    data = cls._parse_data(data)
  File "....\lib\site-packages\telegram\_telegramobject.py", line 385, in _parse_data
    return data.copy()
AttributeError: 'NoneType' object has no attribute 'copy'

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions