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

Bug: Mail contrib: Negative indexing is not supported error #1311

Closed
Panzerbyte opened this issue Apr 20, 2017 · 7 comments
Closed

Bug: Mail contrib: Negative indexing is not supported error #1311

Panzerbyte opened this issue Apr 20, 2017 · 7 comments
Labels
bug An actual error or unwanted behavior.

Comments

@Panzerbyte
Copy link

Brief summary of issue:

After having implemented the mail.py contrib module, I started to fiddle around with it and saw that after inputting @mail 1 (to check mail with id 1) it would be executed as it should be.
However, when you try a negative number, like @mail 0, it would give the Assertion Error: Negative indexing is not supported, which is generated from the django package.

Steps to reproduce the issue:

  1. Implement the mail.py module from evennia/contrib
  2. Type in '@mail 0' or '@mail -42' for example

Error output

Traceback (most recent call last):
  File "c:\mud\evennia\evennia\commands\cmdhandler.py", line 509, in _run_command
    ret = yield cmd.func()
  File ".\commands\mail.py", line 214, in func
    message = self.get_all_mail()[int(self.lhs) - 1]
  File "c:\mud\pyenv\Lib\site-packages\django\db\models\query.py", line 277, in __getitem__
    "Negative indexing is not supported."
AssertionError: Negative indexing is not supported.

Extra information, such as Evennia revision/repo/branch, operating system and ideas for how to solve:

Happened on rev ae2c2be, but doesn't matter which revision as long as the mail.py contrib module is implemented in the system.

@Griatch
Copy link
Member

Griatch commented Apr 20, 2017

This is because it is trying to index in a queryset, which does not support negative indexing. This should be handled as part of the input verification. Pinging @grungies1138 in case he wants to peek at it.

@Griatch Griatch added the bug An actual error or unwanted behavior. label Apr 20, 2017
@Griatch Griatch changed the title Assertion Error: Negative indexing is not supported Bug: Mail contrib: Negative indexing is not supported error Apr 20, 2017
@grungies1138
Copy link
Contributor

Most likely raised because someone typed @mail 0. The table that shows the list of messages is a 1-based index, but the in-memory list is 0-based. the -1 is to allow for selection of the list item based on it's position in the list. If the user is using a 0-based attempt to pull the message, then they will not get the right message, regardless of the number they enter. Best I can do/recommend is to catch then entrance of a 0 in the input and display a message. Unless someone else has a better idea.

@Panzerbyte
Copy link
Author

Indeed to catch the input of a 0 on @mail is what I thought about - just lack the knowledge about the system to implement it.

@BlauFeuer
Copy link
Contributor

This might work as a technique to get it in range: once the input string is converted to a number, to make sure the value is positive and an integer:
value = int(max(1, value))

@TehomCD
Copy link
Contributor

TehomCD commented Apr 21, 2017

Maybe something like:

                    try:
                        num = int(self.lhs) - 1
                        if num < 0:
                            raise ValueError
                        message = self.get_all_mail()[num]
                    except (ValueError, IndexError):
                        self.caller.msg("'%s' is not a valid mail id." % self.lhs)
                        return

That way you're using the same error message.

@Griatch
Copy link
Member

Griatch commented Sep 13, 2017

@grungies1138 Are you interested in resolving this?

@Griatch
Copy link
Member

Griatch commented Sep 30, 2017

I fixed the contrib with more elaborate index error checking. So this should not happen any more. Closing.

@Griatch Griatch closed this as completed Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An actual error or unwanted behavior.
Projects
None yet
Development

No branches or pull requests

5 participants