From 89ea0d1a239c42106ca10948f7f253fca4204dee Mon Sep 17 00:00:00 2001 From: Petr Lavrov Date: Sun, 29 Jun 2025 23:53:31 +0300 Subject: [PATCH 1/2] v0.10.29 - Handle message edit exceptions in user interactions user_interactions.py - added handling for TelegramBadRequest with a specific check for "message to edit not found" - added debug and warning logs for message edit failures --- botspot/components/features/user_interactions.py | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/botspot/components/features/user_interactions.py b/botspot/components/features/user_interactions.py index 419616a..7c6fa68 100644 --- a/botspot/components/features/user_interactions.py +++ b/botspot/components/features/user_interactions.py @@ -3,6 +3,7 @@ from typing import Dict, List, Optional, Union from aiogram import Bot, F, types +from aiogram.exceptions import TelegramBadRequest from aiogram.fsm.context import FSMContext from aiogram.fsm.state import State, StatesGroup from aiogram.types import InaccessibleMessage, InlineKeyboardButton, InlineKeyboardMarkup, Message @@ -444,6 +445,12 @@ async def handle_choice_callback(callback_query: types.CallbackQuery, state: FSM new_text = f"{callback_query.message.text}\n\nSelected: {choice}" try: await callback_query.message.edit_text(new_text) + except TelegramBadRequest as e: + if "message to edit not found" in e.message: + # This can happen if the message was deleted or edited by another process + logger.debug("Message was cleaned up, skipping edit") + else: + logger.warning(f"Failed to edit message after choice selection: {e}") except Exception as e: logger.warning(f"Failed to edit message after choice selection: {e}") diff --git a/pyproject.toml b/pyproject.toml index 6aad166..72f73f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "botspot" -version = "0.10.28" +version = "0.10.29" description = "" readme = "README.md" authors = [ From 9e59cf1785ba474e940f7111ed8a523c7af4e325 Mon Sep 17 00:00:00 2001 From: Petr Lavrov Date: Mon, 30 Jun 2025 01:27:14 +0300 Subject: [PATCH 2/2] v0.10.30 - Fix JSON serialization in queue_manager queue_manager.py - Fixed item.model_dump to correctly serialize enums and non-BSON types using mode="json" --- botspot/components/new/queue_manager.py | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/botspot/components/new/queue_manager.py b/botspot/components/new/queue_manager.py index 2f87db9..11b7457 100644 --- a/botspot/components/new/queue_manager.py +++ b/botspot/components/new/queue_manager.py @@ -88,8 +88,8 @@ async def add_item(self, item: T, user_id: Optional[int] = None): raise QueuePermissionError("user_id is required unless single_user_mode is enabled") - # Todo: do I need the mode="json" here? - doc = item.model_dump(by_alias=True, exclude_none=True) + # Use mode="json" to serialize enums and other non-BSON types correctly + doc = item.model_dump(by_alias=True, exclude_none=True, mode="json") logger.debug(f"Item before enrichment: {doc}") mongo_doc = self.enrich_doc(doc, user_id) diff --git a/pyproject.toml b/pyproject.toml index 72f73f2..8088ef7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "botspot" -version = "0.10.29" +version = "0.10.30" description = "" readme = "README.md" authors = [