mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fix handler registration order in Scene
Previously, `Scene` handlers were registered based on the sorted output of `inspect.getmembers`, causing incorrect execution order. Now, handlers are registered in the order they are defined in the class, ensuring reliable behavior and proper sequence when handling filters with varying specificity. Added test cases to validate the correct handler ordering.
This commit is contained in:
parent
e622ada2fc
commit
d36a10d428
3 changed files with 37 additions and 1 deletions
|
|
@ -1680,3 +1680,31 @@ class TestSceneInheritance:
|
|||
assert child_2_handler.handler is _empty_handler
|
||||
|
||||
assert child_3_handler.handler is not _empty_handler
|
||||
|
||||
|
||||
def collect_handler_names(scene):
|
||||
return [handler.handler.__name__ for handler in scene.__scene_config__.handlers]
|
||||
|
||||
|
||||
class TestSceneHandlersOrdering:
|
||||
def test_correct_ordering(self):
|
||||
class Scene1(Scene):
|
||||
@on.message()
|
||||
async def handler1(self, message: Message) -> None:
|
||||
pass
|
||||
|
||||
@on.message()
|
||||
async def handler2(self, message: Message) -> None:
|
||||
pass
|
||||
|
||||
class Scene2(Scene):
|
||||
@on.message()
|
||||
async def handler2(self, message: Message) -> None:
|
||||
pass
|
||||
|
||||
@on.message()
|
||||
async def handler1(self, message: Message) -> None:
|
||||
pass
|
||||
|
||||
assert collect_handler_names(Scene1) == ["handler1", "handler2"]
|
||||
assert collect_handler_names(Scene2) == ["handler2", "handler1"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue