Skip to content

'args' attribute of 'Command.CommandObj' seems not working #556

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

Closed
y-young opened this issue Apr 4, 2021 · 3 comments · Fixed by #558
Closed

'args' attribute of 'Command.CommandObj' seems not working #556

y-young opened this issue Apr 4, 2021 · 3 comments · Fixed by #558
Assignees
Labels
bug Something is wrong with the framework good first issue A good place to start contributing to this project without going too deep.
Milestone

Comments

@y-young
Copy link

y-young commented Apr 4, 2021

Context

  • Operating System: Windows 10
  • Python Version: 3.8.1
  • aiogram version: 2.12.1
  • aiohttp version: 3.7.3
  • uvloop version (if installed):

Expected Behavior

command.args returns arguments of command

Current Behavior

command.args returns None

Failure Information (for bugs)

It seems the args attribute is not working.

Digging into dispatcher/filters/builtin.py, I found nothing about setting this attribute, but after adding args = text.split()[1] and pass it to the construtor of CommandObj, it seems to work.

I wonder if this is the intended behavior or am I getting it wrong?

I would be glad to open a PR if it's a mistake :)

Steps to Reproduce

@dp.message_handler(commands=['test'])
async def test(message: Message, command: Command.CommandObj):
    print(command, command.args)

Test command: /test abc

Failure Logs

Output: Command.CommandObj(prefix='/', command='test', mention='') None

@darksidecat
Copy link
Contributor

args = text.split()[1]

This can raise IndexError exception when the command has no arguments. Also a command can have multiple arguments, so it makes sense to use a slice to handle such cases.
args = text.split()[1:]

@y-young
Copy link
Author

y-young commented Apr 6, 2021

args = text.split()[1]

This can raise IndexError exception when the command has no arguments. Also a command can have multiple arguments, so it makes sense to use a slice to handle such cases.
args = text.split()[1:]

Yes that's a mistake.
So is this a bug or an intended behavior?

@darksidecat
Copy link
Contributor

So is this a bug or an intended behavior?

Looks like a bug. I think you can be free to make pull request.
@evgfilim1 WDYT?

@evgfilim1 evgfilim1 added the bug Something is wrong with the framework label Apr 24, 2021
@evgfilim1 evgfilim1 added the good first issue A good place to start contributing to this project without going too deep. label Apr 24, 2021
@evgfilim1 evgfilim1 added this to the 2.13 milestone Apr 28, 2021
JrooTJunior pushed a commit that referenced this issue Apr 28, 2021
* fix: builtin command filter args

* fix: use string for command arguments

* fix: text property of command object

Co-authored-by: evgfilim1 <evgfilim1@yandex.ru>

Co-authored-by: evgfilim1 <evgfilim1@yandex.ru>
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 good first issue A good place to start contributing to this project without going too deep.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants