mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
Prevent endless loop with buttons (#1626)
* fix: prevent endless loop with buttons * test: added test for add w/o max width * docs: added changelog record * chore: explicit set max_width 0
This commit is contained in:
parent
7b07338851
commit
e17c84144d
3 changed files with 17 additions and 3 deletions
1
CHANGES/1595.bugfix.rst
Normal file
1
CHANGES/1595.bugfix.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fixed endless loop while adding buttons to the :code:`KeyboardBuilder`.
|
||||
|
|
@ -179,9 +179,12 @@ class KeyboardBuilder(Generic[ButtonType], ABC):
|
|||
last_row.extend(head)
|
||||
|
||||
# Separate buttons to exclusive rows with max possible row width
|
||||
while buttons:
|
||||
row, buttons = buttons[: self.max_width], buttons[self.max_width :]
|
||||
markup.append(list(row))
|
||||
if self.max_width > 0:
|
||||
while buttons:
|
||||
row, buttons = buttons[: self.max_width], buttons[self.max_width :]
|
||||
markup.append(list(row))
|
||||
else:
|
||||
markup.append(list(buttons))
|
||||
|
||||
self._markup = markup
|
||||
return self
|
||||
|
|
|
|||
|
|
@ -170,6 +170,16 @@ class TestKeyboardBuilder:
|
|||
if last_columns:
|
||||
assert len(markup[-1]) == last_columns
|
||||
|
||||
def test_add_wo_max_width(self):
|
||||
builder = KeyboardBuilder(button_type=KeyboardButton)
|
||||
builder.max_width = 0
|
||||
count = 42
|
||||
|
||||
for index in range(count):
|
||||
builder.add(KeyboardButton(text=f"btn-{index}"))
|
||||
|
||||
assert len(list(builder.buttons)) == count
|
||||
|
||||
def test_row(
|
||||
self,
|
||||
):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue