Fix #1743: scene handling for channel updates (#1763)

* Fix scene handling for channel updates with missing FSM state (#1743)

* Add changelog entry for scene handling fix

* Refine scene context error handling
This commit is contained in:
Kostiantyn Kriuchkov 2026-02-10 23:08:44 +02:00 committed by GitHub
parent 1708980ceb
commit da7bfdca0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 298 additions and 4 deletions

View file

@ -309,6 +309,34 @@ class TestSceneHandlerWrapper:
# Check whether result is correct
assert result == 42
async def test_scene_handler_wrapper_call_without_scene_context(self):
class MyScene(Scene):
pass
async def handler_mock(*args, **kwargs):
return 42
event_update_mock = Update(
update_id=42,
message=Message(
message_id=42,
text="test",
date=datetime.now(),
chat=Chat(
type="private",
id=42,
),
),
)
scene_handler_wrapper = SceneHandlerWrapper(MyScene, handler_mock)
with pytest.raises(
SceneException,
match="Scene context key 'state' is not available. Ensure FSM is enabled and pipeline is intact.",
):
await scene_handler_wrapper(event_update_mock, event_update=event_update_mock)
def test_scene_handler_wrapper_str(self):
class MyScene(Scene):
pass
@ -1558,6 +1586,27 @@ class TestSceneRegistry:
handler.assert_called_once_with(event, data)
assert result == handler.return_value
async def test_scene_registry_update_middleware_without_state(self):
router = Router()
registry = SceneRegistry(router)
handler = AsyncMock(spec=NextMiddlewareType)
event = Update(
update_id=42,
message=Message(
message_id=42,
text="test",
date=datetime.now(),
chat=Chat(id=42, type="private"),
),
)
data = {}
result = await registry._update_middleware(handler, event, data)
assert "scenes" not in data
handler.assert_called_once_with(event, data)
assert result == handler.return_value
async def test_scene_registry_update_middleware_not_update(self, bot: MockedBot):
router = Router()
registry = SceneRegistry(router)
@ -1604,6 +1653,24 @@ class TestSceneRegistry:
handler.assert_called_once_with(event, data)
assert result == handler.return_value
async def test_scene_registry_middleware_without_state(self):
router = Router()
registry = SceneRegistry(router)
handler = AsyncMock(spec=NextMiddlewareType)
event = Message(
message_id=42,
text="test",
date=datetime.now(),
chat=Chat(id=42, type="private"),
)
data = {}
result = await registry._middleware(handler, event, data)
assert "scenes" not in data
handler.assert_called_once_with(event, data)
assert result == handler.return_value
class TestSceneInheritance:
def test_inherit_handlers(self):