From 2529f7466f58e37b106ce6a9c4cbc3894c81b902 Mon Sep 17 00:00:00 2001 From: kbchip Date: Tue, 17 Nov 2026 21:54:46 -0700 Subject: [PATCH 1/4] Fix lastgenre auto mode ignores singletons and add unit test Fixes #7190 --- beetsplug/lastgenre/__init__.py | 7 ++++++- test/plugins/test_lastgenre.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 01cb1f6ee7..cc158d365b 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -137,6 +137,7 @@ def setup(self) -> None: """Setup plugin from config options""" if self.config["auto"]: self.import_stages = [self.imported] + self.register_listener("item_imported", self.item_imported) self.whitelist: Whitelist = self._load_whitelist() self.c14n_branches: CanonTree @@ -823,4 +824,8 @@ def lastgenre_func( return [lastgenre_cmd] def imported(self, _: ImportSession, task: ImportTask) -> None: - self._process(task.album if task.is_album else task.item, write=False) # type: ignore[attr-defined] + if task.is_album: + self._process(task.album, write=False) + + def item_imported(self, _: library.Library, item: Item) -> None: + self._process(item, write=False) diff --git a/test/plugins/test_lastgenre.py b/test/plugins/test_lastgenre.py index 9489c2789e..9024c41314 100644 --- a/test/plugins/test_lastgenre.py +++ b/test/plugins/test_lastgenre.py @@ -160,6 +160,19 @@ def unexpected_store(*_, **__): assert album.genres == ["Original Genre"] assert album.items()[0].genres == ["Original Genre"] + def test_item_imported_processes_singleton(self): + item = self.create_item( + album="Singleton Album", + albumartist="Singleton Artist", + artist="Singleton Artist", + title="Singleton Track", + ) + + with patch.object(self.plugin, "_process") as process: + self.plugin.item_imported(self.lib, item) + + process.assert_called_once_with(item, write=False) + def test_no_duplicate(self): """Remove duplicated genres.""" self._setup_config(count=99) From f4e178c34b477433251a2287c3a966ba8d2c4fb5 Mon Sep 17 00:00:00 2001 From: Chip H Date: Tue, 17 Nov 2026 22:09:45 -0700 Subject: [PATCH 2/4] Add changes to docs/changelog.rst --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 60080c7a8c..13def33556 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -167,6 +167,8 @@ Bug fixes instead of silently falling back to plain lyrics. :bug:`7070` - :doc:`plugins/info`: Fix a :class:`TypeError` when printing list-valued tag fields with non-string elements, such as ``synced_lyrics``. :bug:`7183` +- :doc:`plugins/lastgenre`: Fix lastgenre not triggering on singleton imports + in auto mode. :bug:`7190` For plugin developers ~~~~~~~~~~~~~~~~~~~~~ From 37e41fc99d0c7c472d968d4bb639b9c984131dce Mon Sep 17 00:00:00 2001 From: kbchip Date: Tue, 17 Nov 2026 22:15:31 -0700 Subject: [PATCH 3/4] Format docs/changelog.rst with poe --- docs/changelog.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 13def33556..4db2b225ac 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -167,8 +167,8 @@ Bug fixes instead of silently falling back to plain lyrics. :bug:`7070` - :doc:`plugins/info`: Fix a :class:`TypeError` when printing list-valued tag fields with non-string elements, such as ``synced_lyrics``. :bug:`7183` -- :doc:`plugins/lastgenre`: Fix lastgenre not triggering on singleton imports - in auto mode. :bug:`7190` +- :doc:`plugins/lastgenre`: Fix lastgenre not triggering on singleton imports in + auto mode. :bug:`7190` For plugin developers ~~~~~~~~~~~~~~~~~~~~~ From caa10cb511716e56310ce001ef7e4aa8b4a63045 Mon Sep 17 00:00:00 2001 From: kbchip Date: Tue, 17 Nov 2026 22:21:09 -0700 Subject: [PATCH 4/4] Fix erroneous item_imported() definition in beetsplug/lastgenre/__init__.py --- beetsplug/lastgenre/__init__.py | 10 ++++++---- test/plugins/test_lastgenre.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 509dc262f5..408ddb5baa 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -15,12 +15,12 @@ from collections import defaultdict from functools import cached_property, singledispatchmethod from pathlib import Path -from typing import TYPE_CHECKING, Any, Protocol +from typing import TYPE_CHECKING, Any, Protocol, Unpack import confuse import yaml -from beets import config, library, plugins, ui +from beets import config, events, library, plugins, ui from beets.library import Album, Item from beets.util import plurality, unique_list from beetsplug.lastgenre.utils import is_ignored, normalize_genre @@ -830,5 +830,7 @@ def imported(self, _: ImportSession, task: ImportTask) -> None: if task.is_album: self._process(task.album, write=False) - def item_imported(self, _: library.Library, item: Item) -> None: - self._process(item, write=False) + def item_imported( + self, **kwargs: Unpack[events.ItemImportedEventArgs] + ) -> None: + self._process(kwargs["item"], write=False) diff --git a/test/plugins/test_lastgenre.py b/test/plugins/test_lastgenre.py index 2f8208e59a..1e510cf6de 100644 --- a/test/plugins/test_lastgenre.py +++ b/test/plugins/test_lastgenre.py @@ -169,7 +169,7 @@ def test_item_imported_processes_singleton(self): ) with patch.object(self.plugin, "_process") as process: - self.plugin.item_imported(self.lib, item) + self.plugin.item_imported(lib=self.lib, item=item) process.assert_called_once_with(item, write=False)