Skip to content

Data Not Being Passed from Parent Router's Filter to Handler in Inherited Router #1266

Closed
@Latand

Description

@Latand

Checklist

  • I am sure the error is coming from aiogram code
  • I have searched in the issue tracker for similar bug reports, including closed ones

Operating system

Windows 10

Python version

3.10

aiogram version

3.0.0rc1

Expected behavior

When the command "/admin" is sent to the bot, the filter AdminFilter should identify whether the text "admin" is present in the message. If it is, the is_admin variable should be passed to the admin_command_handler, allowing it to execute its logic.

Current behavior

The variable is_admin is not being passed to the admin_command_handler, resulting in an error indicating that the variable is not defined.

Steps to reproduce

  1. Replace "YOUR_TOKEN_HERE" with your bot token in the code snippet.
  2. Run the code.
  3. Send the "/admin" command to the bot.
  4. Observe the error indicating that the variable is_admin is not defined.

Code example

import asyncio
import logging
import sys

from aiogram import Bot, Dispatcher, Router
from aiogram.filters import BaseFilter, Command

dp = Dispatcher()
token = "YOUR_TOKEN_HERE"
bot = Bot(token)


class IsAdmins(BaseFilter):
    async def __call__(self, message):
        if "admin" in message.text.casefold():
            return {"is_admin": True}
        return False



async def admin_command_handler(message, is_admin: bool):
    await message.answer(f"Admin Command Handler, is_admin: {is_admin}")



admin_router = Router()
admin_router.message.filter(IsAdmins())

admin_command_router = Router()

admin_router.include_router(admin_command_router)
dp.include_router(admin_router)

admin_command_router.message.register(adm_com_router, Command("admin"))


async def main():
    await dp.start_polling(bot)


logging.basicConfig(level=logging.INFO, stream=sys.stdout)

asyncio.run(main())

Logs

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is wrong with the framework

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions