Fix 'from_scratch': delete all tags before writing new tags to file (#5828)

Fixes #3706.

### Issue
Comment tags are written to file even if option 'from_scratch' is used.
The same tags are not written to the file if imported together with
other files as album. Therefore 'from_scratch' is not working as
described in the documentation.

### Solution
1. Add test: Adapt the function from the 'regular' import class and
insert it in the class for the singleton import test.
2. Fix bug : Add check for 'from_scratch' option. If used, clear
metadata before applying 'new' metadata with autotag.
3. No documentation change needed. Option now works as described in the
documentation.
4. Add changelog.
This commit is contained in:
Šarūnas Nejus 2026-01-15 15:43:19 +00:00 committed by GitHub
commit 679cfc93ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View file

@ -680,6 +680,8 @@ class SingletonImportTask(ImportTask):
return [self.item]
def apply_metadata(self):
if config["import"]["from_scratch"]:
self.item.clear()
autotag.apply_item_metadata(self.item, self.match.info)
def _emit_imported(self, lib):

View file

@ -90,6 +90,8 @@ Bug fixes:
- :doc:`/plugins/ftintitle`: Fixed artist name splitting to prioritize explicit
featuring tokens (feat, ft, featuring) over generic separators (&, and),
preventing incorrect splits when both are present.
- :doc:`reference/cli`: Fix 'from_scratch' option for singleton imports: delete
all (old) metadata when new metadata is applied. :bug:`3706`
For plugin developers:

View file

@ -258,6 +258,17 @@ class ImportSingletonTest(AutotagImportTestCase):
assert self.lib.items().get().title == "Applied Track 1"
assert (self.lib_path / "singletons" / "Applied Track 1.mp3").exists()
def test_apply_from_scratch_removes_other_metadata(self):
config["import"]["from_scratch"] = True
for mediafile in self.import_media:
mediafile.comments = "Tag Comment"
mediafile.save()
self.importer.add_choice(importer.Action.APPLY)
self.importer.run()
assert self.lib.items().get().comments == ""
def test_skip_does_not_add_track(self):
self.importer.add_choice(importer.Action.SKIP)
self.importer.run()