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

Fixed bug in get_all_mail. #1262

Closed
wants to merge 1 commit into from
Closed

Fixed bug in get_all_mail. #1262

wants to merge 1 commit into from

Conversation

grungies1138
Copy link
Contributor

db_receivers_players=self.caller needed to be changed to self.caller.player

Brief overview of PR changes/additions

Motivation for adding to Evennia

Other info (issues closed, discussion etc)

db_receivers_players=self.caller needed to be changed to self.caller.player
@Griatch
Copy link
Member

Griatch commented Mar 20, 2017

This change causes it to fail its unittest.

@eldritchsemblance
Copy link
Contributor

The test failure is almost identical to the issue I fixed in PR #1265, where the evennia making an assumption about whether the account is ooc or puppeting. Maybe that determination needs to be baked in at a higher level in the code?

@BlauFeuer
Copy link
Contributor

Here are the tests for this contrib at https://github.com/evennia/evennia/blob/master/evennia/contrib/tests.py#L540

It's helpful to know which test failed and what error was given, so I ran
evennia test evennia

Running the test without patching passes:
``
Ran 200 tests in 67.216s

OK

But then adding the PR and re-running:

ERROR: test_mail (evennia.contrib.tests.TestMail)

Traceback (most recent call last):
File "/home/evennia/evennia/evennia/contrib/tests.py", line 542, in test_mail
self.call(mail.CmdMail(), "2", "'2' is not a valid mail id.", caller=self.player)
File "/home/evennia/evennia/evennia/commands/default/tests.py", line 68, in call
cmdobj.func()
File "/home/evennia/evennia/evennia/contrib/mail.py", line 209, in func
message = self.get_all_mail()[int(self.lhs) - 1]
File "/home/evennia/evennia/evennia/contrib/mail.py", line 90, in get_all_mail
messages = Msg.objects.get_by_tag(category="mail", raw_queryset=True).filter(db_receivers_players=self.caller.player)
AttributeError: 'DefaultPlayer' object has no attribute 'player'


Ran 200 tests in 66.805s

FAILED (errors=1)


@eldritchsemblance
Copy link
Contributor

This error can happen anywhere a command that is available both ooc and puppeting and something on the Player (or Account, post #1174) needs to be accessed. Checking for the AttributeError exception every time .player is accessed seems to be not very DRY.

@BlauFeuer
Copy link
Contributor

Confusion about self.caller goes away when code uses self.character and self.player instead. None of my code ever uses self.caller to assume anything more than "the object that initiated the command".

@eldritchsemblance
Copy link
Contributor

@BlauFeuer If that's the case I'm going to revisit #1265

@BlauFeuer
Copy link
Contributor

The default commands inherit from evennia.commands.default.muxcommand.MuxCommand, and so the caveat is ...

this code only engages when self.player_caller == True

@eldritchsemblance
Copy link
Contributor

So the fix for this should just be to use self.player then.

@BlauFeuer
Copy link
Contributor

@eldritchsemblance If you changed line 91 to filter on db_receivers_players=self.player it would still pass unit tests, but wouldn't be a functional mail system when used as a player or a character command as written.

If you just add self.player_caller = True to CmdMail, then, just like applying the PR, it works as a player or a character command, but doesn't pass unit tests.

This leads me to believe that a successful PR would have to also update the unit tests.

@eldritchsemblance
Copy link
Contributor

eldritchsemblance commented Mar 29, 2017

@BlauFeuer @grungies1138 The change as is simply changes the point of failure from while puppeting to while ooc. The same change I applied to #1265 before @BlauFeuer advice works here, all unit tests pass, and the mail system works both ooc and while puppeting:

try:
            player = self.caller.player
except AttributeError:
            player = self.caller
messages = Msg.objects.get_by_tag(category="mail", raw_queryset=True).filter(db_receivers_players=player)

Fixed this in pull request #1289

@Griatch
Copy link
Member

Griatch commented Mar 29, 2017

The regression was fixed by @eldritchsemblance in #1289. Closing.

@Griatch Griatch closed this Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants