mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
* 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:
parent
1708980ceb
commit
da7bfdca0c
6 changed files with 298 additions and 4 deletions
|
|
@ -70,6 +70,9 @@ class FSMContextMiddleware(BaseMiddleware):
|
|||
) -> FSMContext | None:
|
||||
if chat_id is None:
|
||||
chat_id = user_id
|
||||
elif user_id is None and self.strategy in {FSMStrategy.CHAT, FSMStrategy.CHAT_TOPIC}:
|
||||
# CHAT/CHAT_TOPIC are chat-scoped, so missing user_id can fallback to chat_id.
|
||||
user_id = chat_id
|
||||
|
||||
if chat_id is not None and user_id is not None:
|
||||
chat_id, user_id, thread_id = apply_strategy(
|
||||
|
|
|
|||
|
|
@ -248,8 +248,16 @@ class SceneHandlerWrapper:
|
|||
event: TelegramObject,
|
||||
**kwargs: Any,
|
||||
) -> Any:
|
||||
state: FSMContext = kwargs["state"]
|
||||
scenes: ScenesManager = kwargs["scenes"]
|
||||
try:
|
||||
state: FSMContext = kwargs["state"]
|
||||
scenes: ScenesManager = kwargs["scenes"]
|
||||
except KeyError as error:
|
||||
missing_key = error.args[0]
|
||||
msg = (
|
||||
f"Scene context key {missing_key!r} is not available. "
|
||||
"Ensure FSM is enabled and pipeline is intact."
|
||||
)
|
||||
raise SceneException(msg) from None
|
||||
event_update: Update = kwargs["event_update"]
|
||||
scene = self.scene(
|
||||
wizard=SceneWizard(
|
||||
|
|
@ -768,12 +776,15 @@ class SceneRegistry:
|
|||
data: dict[str, Any],
|
||||
) -> Any:
|
||||
assert isinstance(event, Update), "Event must be an Update instance"
|
||||
state = data.get("state")
|
||||
if state is None:
|
||||
return await handler(event, data)
|
||||
|
||||
data["scenes"] = ScenesManager(
|
||||
registry=self,
|
||||
update_type=event.event_type,
|
||||
event=event.event,
|
||||
state=data["state"],
|
||||
state=state,
|
||||
data=data,
|
||||
)
|
||||
return await handler(event, data)
|
||||
|
|
@ -784,12 +795,16 @@ class SceneRegistry:
|
|||
event: TelegramObject,
|
||||
data: dict[str, Any],
|
||||
) -> Any:
|
||||
state = data.get("state")
|
||||
if state is None:
|
||||
return await handler(event, data)
|
||||
|
||||
update: Update = data["event_update"]
|
||||
data["scenes"] = ScenesManager(
|
||||
registry=self,
|
||||
update_type=update.event_type,
|
||||
event=event,
|
||||
state=data["state"],
|
||||
state=state,
|
||||
data=data,
|
||||
)
|
||||
return await handler(event, data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue