Refactor startup and shutdown handlers in bot initialization for compatibility with aiogram event signature
- Wrapped the startup and shutdown handlers to ensure they conform to the aiogram event signature, allowing for proper argument handling. - Updated the web server to access dispatcher workflow data directly, preventing sequence protocol issues and enhancing stability.
This commit is contained in:
@@ -31,8 +31,9 @@ async def build_and_start_web_app(
|
||||
"tribute_service",
|
||||
"panel_webhook_service",
|
||||
):
|
||||
if key in dp: # type: ignore
|
||||
app[key] = dp[key] # type: ignore
|
||||
# Access dispatcher workflow_data directly to avoid sequence protocol issues
|
||||
if hasattr(dp, "workflow_data") and key in dp.workflow_data: # type: ignore
|
||||
app[key] = dp.workflow_data[key] # type: ignore
|
||||
|
||||
setup_application(app, dp, bot=bot)
|
||||
|
||||
|
||||
+7
-2
@@ -260,8 +260,13 @@ async def run_bot(settings_param: Settings):
|
||||
dp["panel_service"] = services["panel_service"]
|
||||
dp["async_session_factory"] = local_async_session_factory
|
||||
|
||||
dp.startup.register(on_startup_configured)
|
||||
dp.shutdown.register(on_shutdown_configured)
|
||||
# Wrap startup/shutdown handlers to satisfy aiogram event signature (no args passed)
|
||||
async def _on_startup_wrapper():
|
||||
await on_startup_configured(dp)
|
||||
async def _on_shutdown_wrapper():
|
||||
await on_shutdown_configured(dp)
|
||||
dp.startup.register(_on_startup_wrapper)
|
||||
dp.shutdown.register(_on_shutdown_wrapper)
|
||||
|
||||
await register_all_routers(dp, settings_param)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user