diff --git a/beets/importer.py b/beets/importer.py index bd16c244e..3e288c271 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -576,17 +576,17 @@ class ImportTask(BaseImportTask): """Sets the fields given at CLI or configuration to the specified values, for both the album and all its items. """ + items = self.imported_items() + for field, view in config['import']['set_fields'].items(): + value = view.get() + log.debug(u'Set field {1}={2} for {0}', + displayable_path(self.paths), + field, + value) + self.album[field] = value + for item in items: + item[field] = value with lib.transaction(): - items = self.imported_items() - for field, view in config['import']['set_fields'].items(): - value = view.get() - log.debug(u'Set field {1}={2} for {0}', - displayable_path(self.paths), - field, - value) - self.album[field] = value - for item in items: - item[field] = value for item in items: item.store() self.album.store() @@ -956,15 +956,14 @@ class SingletonImportTask(ImportTask): """Sets the fields given at CLI or configuration to the specified values, for the singleton item. """ - with lib.transaction(): - for field, view in config['import']['set_fields'].items(): - value = view.get() - log.debug(u'Set field {1}={2} for {0}', - displayable_path(self.paths), - field, - value) - self.item[field] = value - self.item.store() + for field, view in config['import']['set_fields'].items(): + value = view.get() + log.debug(u'Set field {1}={2} for {0}', + displayable_path(self.paths), + field, + value) + self.item[field] = value + self.item.store() # FIXME The inheritance relationships are inverted. This is why there diff --git a/test/test_importer.py b/test/test_importer.py index a80fc9de8..e581f282a 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -743,7 +743,6 @@ class ImportTest(_common.TestCase, ImportHelper): comments = u"managed by beets" config['import']['set_fields'] = { - u'collection': collection, u'genre': genre, u'comments': comments } @@ -756,11 +755,10 @@ class ImportTest(_common.TestCase, ImportHelper): for album in self.lib.albums(): album.load() # TODO: Not sure this is necessary. self.assertEqual(album.genre, genre) - self.assertEqual(album.collection, collection) + self.assertEqual(album.comments, comments) for item in album.items(): - self.assertEqual(item.genre, genre) - self.assertEqual(item.collection, collection) - self.assertEqual(item.comments, comments) + self.assertEqual(item.get("genre", with_album=False), genre) + self.assertEqual(item.get("comments", with_album=False), comments) # Remove album from library to test again with APPLY choice. album.remove() @@ -773,11 +771,10 @@ class ImportTest(_common.TestCase, ImportHelper): for album in self.lib.albums(): album.load() self.assertEqual(album.genre, genre) - self.assertEqual(album.collection, collection) + self.assertEqual(album.comments, comments) for item in album.items(): - self.assertEqual(item.genre, genre) - self.assertEqual(item.collection, collection) - self.assertEqual(item.comments, comments) + self.assertEqual(item.get("genre", with_album=False), genre) + self.assertEqual(item.get("comments", with_album=False), comments) class ImportTracksTest(_common.TestCase, ImportHelper):