Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion beetsplug/lastgenre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

import logging
import os
import re
from collections import defaultdict
Expand Down Expand Up @@ -717,7 +718,11 @@ def _fetch_and_log_genre(self, obj: LibModel) -> None:
obj.genres, label = self._get_genre(obj)
self._log.debug("Resolved ({}): {}", label, obj.genres)

ui.show_model_changes(obj, fields=["genres"], print_obj=False)
# Only print the changes if INFO logs are enabled. That is the case when
# running the command, but not during an import (unless it is verbose),
# where printed output can appear on top of the importer's prompt.
Comment on lines +721 to +723

@JOJ0 JOJ0 Nov 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe shorten this. a very short comment why it is here would be sufficient, leaving out the technical details we read in the code anyway. thanks

if self._log.isEnabledFor(logging.INFO):
ui.show_model_changes(obj, fields=["genres"], print_obj=False)

@singledispatchmethod
def _process(self, obj: LibModel, write: bool) -> None:
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ Bug fixes
``Hybrid SACD (SACD layer, 2 channels)``) or the sides of a DualDisc, the
album's ``media`` is now their common format (``Hybrid SACD``) instead of the
generic ``Media``. Releases mixing different formats still get ``Media``.
- :doc:`plugins/lastgenre`: The genre changes are no longer printed during an
import (unless it is verbose), where they could appear on top of the
importer's prompt for the next album and make the import look frozen. The
``lastgenre`` command still prints them. :bug:`6830`

For plugin developers
~~~~~~~~~~~~~~~~~~~~~
Expand Down
42 changes: 42 additions & 0 deletions test/plugins/test_lastgenre.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,48 @@ def unexpected_store(*_, **__):
assert album.genres == ["Original Genre"]
assert album.items()[0].genres == ["Original Genre"]

def _add_album_for_import(self) -> Album:
item = self.create_item(
album="Import Album",
albumartist="Import Artist",
artist="Import Artist",
title="Import Track",
)
return self.lib.add_album([item])

def _run_import_stage(self, album):
"""Run the import stage as the importer does, return what it printed."""
task = Mock(is_album=True, album=album)
self.io.getoutput()

with patch.object(
self.plugin, "_get_genre", return_value=(["Rock"], "test")
):
for stage in self.plugin.get_import_stages():
stage(Mock(), task)

return self.io.getoutput()

def test_import_stage_does_not_print_genre_changes(self):
"""The import stage must not print by default.

See #6830: the printed genre changes appeared on top of the importer's
prompt for the next album, which made the import look frozen.
"""
self.config["verbose"] = 0
album = self._add_album_for_import()

assert self._run_import_stage(album) == ""

album.load()
assert album.genres == ["Rock"]

def test_import_stage_prints_genre_changes_when_verbose(self):
self.config["verbose"] = 1
album = self._add_album_for_import()

assert "genres:" in self._run_import_stage(album)

def test_no_duplicate(self):
"""Remove duplicated genres."""
self._setup_config(count=99)
Expand Down
Loading