Skip to content

Avoid writing unknown track and disc totals#6655

Open
Tsuizxgo wants to merge 2 commits into
beetbox:masterfrom
Tsuizxgo:fix-unknown-track-disc-totals
Open

Avoid writing unknown track and disc totals#6655
Tsuizxgo wants to merge 2 commits into
beetbox:masterfrom
Tsuizxgo:fix-unknown-track-disc-totals

Conversation

@Tsuizxgo
Copy link
Copy Markdown

@Tsuizxgo Tsuizxgo commented May 19, 2026

Description

Fixes #6194.

This PR fixes a small metadata-writing bug in beets.

When tracktotal or disctotal is unknown, beets may store it internally as 0. Before this change, that 0 was written directly into the audio file tags, so some files could end up with metadata like track 1/0 or disc 2/0.

This change treats 0 totals as unknown when writing tags to media files. The actual track and disc numbers are still written, but the unknown total fields are omitted instead of being written as 0.

I also added a regression test to make sure this behavior does not come back later.

To Do

  • Documentation. This is a bug fix in existing behavior and does not add or change any user-facing command or config option.
  • Changelog. Added an entry to docs/changelog.rst.
  • Tests. Added a regression test for writing unknown track and disc totals.

@Tsuizxgo Tsuizxgo requested a review from a team as a code owner May 19, 2026 06:30
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.45%. Comparing base (fc9c02a) to head (b176f42).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6655   +/-   ##
=======================================
  Coverage   72.44%   72.45%           
=======================================
  Files         160      160           
  Lines       20690    20694    +4     
  Branches     3272     3274    +2     
=======================================
+ Hits        14989    14993    +4     
  Misses       4976     4976           
  Partials      725      725           
Files with missing lines Coverage Δ
beets/library/models.py 87.09% <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.

@ShimmerGlass
Copy link
Copy Markdown
Contributor

hey @Tsuizxgo! thank you for your contribution :)

When tracktotal or disctotal is unknown, beets may store it internally as 0

Do you know if this always happens or is it a bug in metadata source(s) ?

@Tsuizxgo
Copy link
Copy Markdown
Author

hey @Tsuizxgo! thank you for your contribution :)

When tracktotal or disctotal is unknown, beets may store it internally as 0

Do you know if this always happens or is it a bug in metadata source(s) ?

Thanks for checking!

It does not necessarily mean that the metadata source explicitly returns 0.

Tracktotal and disctotal are PaddedInt fields in beets, and their null/default value is effectively 0. So if a media file or metadata source does not provide a total value, that missing value can end up represented as 0 inside the beets item/library model. And this bug happened at this time. If the tracktotal and disctotal are not 0, the bug would not happen.

@ShimmerGlass
Copy link
Copy Markdown
Contributor

Your change sets those tags back to None if they are 0, which is certainly better than what we have today.

However this fix is at the last stage: when we write tags. If my understanding is correct things like beet info, using $disctotal, etc. will continue to report 0 when they shouldn't.

their null/default value is effectively 0.

I think that's our core issue here. If we fixed this default value we wouldn't need special handling for these fields, and everything should report None/empty, including the tags.

Wdyt? Would you have time to look into that?

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.

Disable writing "0" to music files for total tracks/discs when values aren't available

2 participants