FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Rate limit override by Vamp1reAchao · Pull Request #5330 · python-telegram-bot/python-telegram-bot · GitHub

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

Filter by extension

Filter by extension .py  (2) .toml  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions changes/unreleased/rate-limit-args-zero.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done, updated the changelog entry and reverted the unrelated test change. Thanks!

harshil21 Aug 15, 2026
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you also fix the failing prek action? Don't worry about the other failing tests

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done, i fix it. Thanks!)


[[pull_requests]]
uid = "5330"
author_uids = ["Vamp1reAchao"]
closes_threads = []
2 changes: 1 addition & 1 deletion src/telegram/ext/_aioratelimiter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
41 changes: 12 additions & 29 deletions tests/ext/test_ratelimiter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].

"""
We mostly test on directly on AIORateLimiter here, b/c BaseRateLimiter doesn't contain anything
Expand Down Expand Up @@ -238,6 +235,17 @@ 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 @@ -408,29 +416,4 @@ async def test_allow_paid_broadcast(self, bot):
await asyncio.sleep(0.1)
# We expect 5 non-apb requests:
# 1: `get_me` from `async with rl_bot`
# 2-5: `send_message`
assert TestAIORateLimiter.count == 5
assert sum(1 for task in non_apb_tasks.values() if task.done()) == 4

# ~2 second after start
# We do the checks once all apb_tasks are done as apparently getting the timings
# right to check after 1 second is hard
await asyncio.sleep(2.1 - 0.1)
assert all(task.done() for task in apb_tasks.values())

apb_call_times = [
ct - TestAIORateLimiter.apb_call_times[0]
for ct in TestAIORateLimiter.apb_call_times
]
apb_call_times_dict = Counter(map(int, apb_call_times))

# We expect ~2000 apb requests after the first second
# 2000 (>>1000), since we have a floating window logic such that an initial
# burst is allowed that is hard to measure in the tests
assert apb_call_times_dict[0] <= 2000
assert apb_call_times_dict[0] + apb_call_times_dict[1] < 3000
assert sum(apb_call_times_dict.values()) == 3000

finally:
# cleanup
await asyncio.gather(*apb_tasks.values(), *non_apb_tasks.values())
# ... (truncated)

Back | FazBrowse Home | New Git URL