Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
Latand opened this issue Aug 14, 2023 · 0 comments · Fixed by #1267
Closed
2 tasks done

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

Latand opened this issue Aug 14, 2023 · 0 comments · Fixed by #1267
Labels
bug Something is wrong with the framework

Comments

@Latand
Copy link
Contributor

Latand commented Aug 14, 2023

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

@Latand Latand added the bug Something is wrong with the framework label Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong with the framework
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant