Skip to content

Command filter doesn't process null mention label properly #1013

Closed
@AbstractiveNord

Description

@AbstractiveNord

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

Ubuntu 20.04, Windows 8

Python version

3.10

aiogram version

3.0b4

Expected behavior

I expect to have these CommandObject instances to be equal

  1. CommandObject(command='start')
  2. Message with text='/start', passed through Command filter.

Current behavior

I did some tests.

Expected :{'command': CommandObject(prefix='/', command='start', mention=None)}
Actual :{'command': CommandObject(prefix='/', command='start', mention='')}

Steps to reproduce

  1. Create a handler with Command filter.
  2. Catch a message with simple '/example' command
  3. Check CommandObject instance, mention will not be None, it's empty string.

Code example

import datetime

import pytest
from aiogram.filters import Command, CommandObject
from aiogram.types import Chat, Message

from tests.mocked_bot import MockedBot  # aiogram/tests/mocked_bot.py


@pytest.mark.parametrize('schema', ['start'])
@pytest.mark.parametrize('input_command', ['/start'])
@pytest.mark.asyncio
async def test_mention_error(schema: str, input_command: str):
    command = Command(commands=schema)
    response = await command.__call__(
        Message(
            message_id=1,
            chat=Chat(
                id=1,
                type="private",
            ),
            text=input_command,
            date=datetime.datetime.now(),
        ),
        MockedBot(),
    )
    assert response == {'command': CommandObject(command='start')}

Logs

============================= test session starts =============================
collecting ... collected 1 item

test_usage.py::test_mention_error[/start-start] FAILED                   [100%]
test_usage.py:9 (test_mention_error[/start-start])
{'command': CommandObject(prefix='/', command='start', mention='')} != {'command': CommandObject(prefix='/', command='start', mention=None)}

Expected :{'command': CommandObject(prefix='/', command='start', mention=None)}
Actual   :{'command': CommandObject(prefix='/', command='start', mention='')}

>       assert response == {'command': CommandObject(command='start')}
E       AssertionError: assert {'command': CommandObject(prefix='/', command='start', mention='')} == {'command': CommandObject(prefix='/', command='start', mention=None)}
E         Differing items:
E         {'command': CommandObject(prefix='/', command='start', mention='')} != {'command': CommandObject(prefix='/', command='start', mention=None)}
E         Full diff:
E         - {'command': CommandObject(prefix='/', command='start', mention=None)}
E         ?                                                                ^^^^
E         + {'command': CommandObject(prefix='/', command='start', mention='')}
E         ?                                                                ^^

Additional information

I know it's not important, None and empty string casts to False, but anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.xIssue or PR for stable 3.x versionbugSomething 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