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

MPDStats Plugin: handle update_rating when item is None / start tests for mpdstats #1443

Merged
merged 1 commit into from Apr 29, 2015

Conversation

CodyReichert
Copy link
Contributor

I had a small issue where I would play a song with MPD that wasn't imported by beets. So, when mpdstats tried to update the rating it would throw up an AttributeError that looks like:

mpdstats: skipped /media/music/tagged/Z-RO/Relvis Presley/09 One More Time.mp3

Traceback (most recent call last):
  File "/usr/bin/beet", line 9, in <module>
    load_entry_point('beets==1.3.14', 'console_scripts', 'beet')()
  File "/home/cody/src/beets/beets/ui/__init__.py", line 1104, in main
    _raw_main(args)
  File "/home/cody/src/beets/beets/ui/__init__.py", line 1094, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/home/cody/src/beets/beetsplug/mpdstats.py", line 360, in func
    MPDStats(lib, self._log).run()
  File "/home/cody/src/beets/beetsplug/mpdstats.py", line 306, in run
    handler(status)
  File "/home/cody/src/beets/beetsplug/mpdstats.py", line 253, in on_stop
    self.handle_song_change(self.now_playing)
  File "/home/cody/src/beets/beetsplug/mpdstats.py", line 233, in handle_song_change
    self.update_rating(song['beets_item'], skipped)
  File "/home/cody/src/beets/beetsplug/mpdstats.py", line 206, in update_rating
    item.load()
AttributeError: 'NoneType' object has no attribute 'load'

Obviously the better fix would be to import the song with beets ;) - but since MPD can play songs that beets may or may not have, it would be good to sanity check it and not kill the plugin.

Also started some tests for mpdstats which checks this!

@@ -203,6 +203,9 @@ def update_item(self, item, attribute, value=None, increment=None):
def update_rating(self, item, skipped):
"""Update the rating for a beets item.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note to the docstring here? Something like

`item` can either be a beets `Item` or None, in which case nothing changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - done!

@sampsyo
Copy link
Member

sampsyo commented Apr 29, 2015

Awesome! Thanks for getting to the bottom of this, and even adding tests. 😃 ✨ 🐟

It looks like this case is already handled for the other events: handle_played and hanlde_skipped call update_item immediately, which already has the null check. Maybe this is worth documenting to make this clearer—the item in the song dict can always be None, so these utilities had better have checks.

@CodyReichert
Copy link
Contributor Author

Not a problem!

I did see where update_item handled the None item, so I tried to keep it consistent since update_rating needs to load the item as well.

@CodyReichert
Copy link
Contributor Author

Alright, squashed commits - and hopefully that fixes the tests!

@sampsyo
Copy link
Member

sampsyo commented Apr 29, 2015

Great! Thank you!

@sampsyo sampsyo merged commit b776a71 into beetbox:master Apr 29, 2015
sampsyo added a commit that referenced this pull request Apr 29, 2015
MPDStats Plugin: handle update_rating when item is None / start tests for mpdstats
sampsyo added a commit that referenced this pull request Apr 29, 2015
CodyReichert pushed a commit to CodyReichert/beets that referenced this pull request May 2, 2015
CodyReichert pushed a commit to CodyReichert/beets that referenced this pull request May 2, 2015
swt30 pushed a commit to swt30/beets that referenced this pull request May 20, 2015
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

2 participants