Skip to content

zero plugin zeroes disctotal if single disc#6306

Open
fredrik wants to merge 1 commit intobeetbox:masterfrom
fredrik:zero-total-discs
Open

zero plugin zeroes disctotal if single disc#6306
fredrik wants to merge 1 commit intobeetbox:masterfrom
fredrik:zero-total-discs

Conversation

@fredrik
Copy link
Contributor

@fredrik fredrik commented Jan 19, 2026

Description

When omit_single_disc is set, disctotal is now also zeroed alongside disc. These tags work together ("Disc 2 of 3") so keeping one without the other is inconsistent.

Previously, only the disc tag was zeroed. This follows from #6015 which made it into v2.5.1 and added the omit_single_disc option.

I've added tests and have used this locally for some time.

To Do

  • Tests
  • Documentation
  • Changelog

@fredrik fredrik requested a review from a team as a code owner January 19, 2026 19:48
@github-actions
Copy link

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.97%. Comparing base (8eed22c) to head (cd9f86a).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6306      +/-   ##
==========================================
- Coverage   68.97%   68.97%   -0.01%     
==========================================
  Files         140      140              
  Lines       18694    18693       -1     
  Branches     3060     3060              
==========================================
- Hits        12894    12893       -1     
  Misses       5153     5153              
  Partials      647      647              
Files with missing lines Coverage Δ
beetsplug/zero.py 94.18% <100.00%> (-0.07%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

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

Just one comment re making this slightly simpler. And it would be good to see a note in the changelog!

Comment on lines 125 to 135
fields_set = False

if "disc" in tags and self.config["omit_single_disc"].get(bool):
if item.disctotal == 1:
if self.config["omit_single_disc"].get(bool) and item.disctotal == 1:
if "disc" in tags:
fields_set = True
self._log.debug("disc: {.disc} -> None", item)
tags["disc"] = None
if "disctotal" in tags:
fields_set = True
self._log.debug("disctotal: {.disctotal} -> None", item)
tags["disctotal"] = None
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify this a little by using beets.ui.show_model_changes, see:

diff --git a/beetsplug/zero.py b/beetsplug/zero.py
index 4623a0c2d..928dda60e 100644
--- a/beetsplug/zero.py
+++ b/beetsplug/zero.py
@@ -21,7 +21,7 @@
 
 from beets.importer import Action
 from beets.plugins import BeetsPlugin
-from beets.ui import Subcommand, input_yn
+from beets.ui import Subcommand, input_yn, show_model_changes
 
 __author__ = "baobab@heresiarch.info"
 
@@ -122,17 +122,9 @@ def set_fields
         Also update the `item` itself if `update_database` is set in the
         config.
         """
-        fields_set = False
-
         if self.config["omit_single_disc"].get(bool) and item.disctotal == 1:
-            if "disc" in tags:
-                fields_set = True
-                self._log.debug("disc: {.disc} -> None", item)
-                tags["disc"] = None
-            if "disctotal" in tags:
-                fields_set = True
-                self._log.debug("disctotal: {.disctotal} -> None", item)
-                tags["disctotal"] = None
+            for tag in {"disc", "disctotal"} & set(tags):
+                tags[tag] = None
 
         if not self.fields_to_progs:
             self._log.warning("no fields list to remove")
@@ -146,13 +138,12 @@ def set_fields
                 match = not progs
 
             if match:
-                fields_set = True
                 self._log.debug("{}: {} -> None", field, value)
                 tags[field] = None
                 if self.config["update_database"]:
                     item[field] = None
 
-        return fields_set
+        return show_model_changes(item)
 
     def process_item(self, item):
         tags = dict(item)

This also has the benefit of changes being reported using the same format and user configuration as beet write and beet update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That looks great, I was not aware! I'll make that change and also update the Changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think show_model_changes works for me here. The plugin defaults to not updating the database and in that case we're not touching item. Please correct me if I'm wrong or if there's another way around this.

I've kept your suggestion for neater iteration and also added changelog and docs entries.

@fredrik
Copy link
Contributor Author

fredrik commented Feb 13, 2026

Obviously, this branch needs to be squashed before merging. ⚠️

Squashed and ready to go.

@fredrik fredrik requested a review from snejus February 13, 2026 22:44
When omit_single_disc is set, disctotal is now also zeroed alongside disc.
Previously, only the disc tag was zeroed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants