From 2262bf91d5ce3e851d5bf7a3bb3f6a03f5243db5 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 24 Aug 2012 00:21:03 +0200 Subject: [PATCH] Fix crash in 'playlistinfo' when called with a songpos not matching an CPID (fixes #162) --- docs/changes.rst | 4 ++++ mopidy/frontends/mpd/protocol/current_playlist.py | 2 +- tests/frontends/mpd/protocol/current_playlist_test.py | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index a2a45960..4dcc8c57 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -14,6 +14,10 @@ v0.8 (in development) and various client support. Requires gevent, which currently is not a dependency of Mopidy. +- Fixed bug when the MPD command `playlistinfo` is used with a track position. + Track position and CPID was intermixed, so it would cause a crash if a CPID + matching the track position didn't exist. (Fixes: :issue:`162`) + v0.7.3 (2012-08-11) =================== diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index 0c2c2d52..c60cbc4a 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -243,7 +243,7 @@ def playlistinfo(context, songpos=None, """ if songpos is not None: songpos = int(songpos) - cp_track = context.backend.current_playlist.get(cpid=songpos).get() + cp_track = context.backend.current_playlist.cp_tracks.get()[songpos] return track_to_mpd_format(cp_track, position=songpos) else: if start is None: diff --git a/tests/frontends/mpd/protocol/current_playlist_test.py b/tests/frontends/mpd/protocol/current_playlist_test.py index 321fc6ee..21889e82 100644 --- a/tests/frontends/mpd/protocol/current_playlist_test.py +++ b/tests/frontends/mpd/protocol/current_playlist_test.py @@ -285,6 +285,8 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertInResponse(u'OK') def test_playlistinfo_with_songpos(self): + # Make the track's CPID not match the playlist position + self.backend.current_playlist.cp_id = 17 self.backend.current_playlist.append([ Track(name='a'), Track(name='b'), Track(name='c'), Track(name='d'), Track(name='e'), Track(name='f'),