diff --git a/beets/importer.py b/beets/importer.py index a902ea38a..0d076f5ba 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -170,18 +170,25 @@ def _infer_album_fields(task): elif task.choice_flag == action.APPLY: # Applying autotagged metadata. Just get AA from the first # item. - if not task.items[0].albumartist: - changes['albumartist'] = task.items[0].artist - if not task.items[0].mb_albumartistid: - changes['mb_albumartistid'] = task.items[0].mb_artistid + for item in task.items: + if item is not None: + first_item = item + break + else: + assert False, "all items are None" + if not first_item.albumartist: + changes['albumartist'] = first_item.artist + if not first_item.mb_albumartistid: + changes['mb_albumartistid'] = first_item.mb_artistid else: assert False # Apply new metadata. for item in task.items: - for k, v in changes.iteritems(): - setattr(item, k, v) + if item is not None: + for k, v in changes.iteritems(): + setattr(item, k, v) def _open_state(): """Reads the state file, returning a dictionary.""" diff --git a/docs/changelog.rst b/docs/changelog.rst index a0ad72170..0c710ef98 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,7 @@ This release focuses on making beets' path formatting vastly more powerful. functions via a plugin, see :ref:`writing-plugins`. * Fix an incompatibility in BPD with libmpc (the library that powers mpc and ncmpc). +* Fix a crash when importing a partial match whose first track was missing. 1.0b11 (December 12, 2011) -------------------------- diff --git a/test/test_importer.py b/test/test_importer.py index be69622df..f87189b56 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -541,6 +541,13 @@ class InferAlbumDataTest(unittest.TestCase): self._infer() self.assertFalse(self.items[0].comp) + def test_first_item_null_apply(self): + self.items[0] = None + self.task.set_choice(({}, self.items)) # APPLY + self._infer() + self.assertFalse(self.items[1].comp) + self.assertEqual(self.items[1].albumartist, self.items[2].artist) + class DuplicateCheckTest(unittest.TestCase): def setUp(self): self.lib = library.Library(':memory:')