Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/unreleased/rate-limit-args-zero.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bugfixes = "Respect an explicit rate_limit_args=0 in AIORateLimiter"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is missing a few more attributes, can you look at the other .tomls and update this?

2 changes: 1 addition & 1 deletion src/telegram/ext/_aioratelimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def process_request(
retries to be made in case of a :exc:`~telegram.error.RetryAfter` exception.
Defaults to :paramref:`AIORateLimiter.max_retries`.
"""
max_retries = rate_limit_args or self._max_retries
max_retries = self._max_retries if rate_limit_args is None else rate_limit_args

group: int | str | bool = False
chat: bool = False
Expand Down
14 changes: 13 additions & 1 deletion tests/ext/test_ratelimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ async def test_max_retries(self, bot, max_retries):
delays = [j - i for i, j in itertools.pairwise(times)]
assert delays == pytest.approx([1.1 for _ in range(max_retries)], rel=0.05)

async def test_rate_limit_args_zero_overrides_default_max_retries(self, bot):
bot = ExtBot(
token=bot.token,
request=self.CountRequest(retry_after=1),
rate_limiter=AIORateLimiter(
max_retries=1, overall_max_rate=0, group_max_rate=0
),
)
with pytest.raises(RetryAfter):
await bot.get_me(rate_limit_args=0)

assert TestAIORateLimiter.count == 1

async def test_delay_all_pending_on_retry(self, bot):
# Makes sure that a RetryAfter blocks *all* pending requests
bot = ExtBot(
Expand Down Expand Up @@ -344,7 +357,6 @@ async def test_rate_limiting_no_chat_id(self, bot):
assert all(task.done() for task in non_chat_tasks.values())
assert all(task.done() for task in chat_tasks.values())
finally:
# cleanup

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this

await asyncio.gather(*non_chat_tasks.values(), *chat_tasks.values())
TestAIORateLimiter.count = 0
TestAIORateLimiter.call_times = []
Expand Down