Use None as default values for multi-valued fields in hooks.Info#6405
Use None as default values for multi-valued fields in hooks.Info#6405
None as default values for multi-valued fields in hooks.Info#6405Conversation
|
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. |
|
Note I cherry-picked the test refactor commit from #6165. |
There was a problem hiding this comment.
Pull request overview
PR make autotag metadata apply stop clearing multi-value fields when tag source give empty list (like genres). This fit core autotag flow so mbsync/tag update not delete existing list data by accident.
Changes:
- Treat
[]same asNonein_apply_metadataunless field allowed inoverwrite_null - Move autotag tests into
test/autotag/and collapse many small apply tests into one data-driven test - Update fixture to include
genres=["Rock","Pop"]so empty-list bug show up in tests
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| beets/autotag/init.py | Skip applying empty lists so existing multi-value fields not wiped |
| test/test_autotag.py | Remove old autotag test module (relocated) |
| test/autotag/test_autotag.py | New autotag test module; adds genres regression coverage and consolidates apply tests |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6405 +/- ##
=======================================
Coverage 69.33% 69.33%
=======================================
Files 141 141
Lines 18793 18793
Branches 3061 3061
=======================================
Hits 13031 13031
Misses 5117 5117
Partials 645 645
🚀 New features to boost your workflow:
|
8327cb3 to
c892548
Compare
|
This looks like it fixes #6403 for me, thanks! |
c3c0bd9 to
b739a1d
Compare
None as default values for multi-valued fields in hooks.Info
Consolidate multiple granular test methods in ApplyTest into a single comprehensive test that validates all applied metadata at once. This improves test maintainability and clarity by: - Replacing ~20 individual test methods with one data-driven test - Using expected data dictionaries to validate all fields together - Removing ApplyCompilationTest class (covered by va=True in main test) - Keeping focused tests for edge cases (artist_credit, date handling) - Switching from BeetsTestCase to standard TestCase for speed - Adding operator import for efficient data extraction The new approach makes it easier to validate all applied metadata at once.
b739a1d to
a8b8aa9
Compare
Fix empty list treated as non-empty field value in
_apply_metadataFixes #6403
Thanks to @aereaux for reporting and helpful debugging!
Problem
In
beets/autotag/__init__.py,_apply_metadataskipped overwriting existing field values withNoneto avoid clearing data unintentionally. However, an empty list ([]) was not treated the same way — it would still overwrite existing field values, effectively clearing multi-valued fields (e.g.genres) when the tag source returned nothing.Fix
Keep multi-value field values as
Noneby default inbeets.autotag.hooks.Infosubclasses:Test changes
genres=["Rock", "Pop"]to the test album fixture to expose the bug: album genres were not being propagated to tracks due to the empty-list issue, since empty track-level genres overwrote them.@pytest.mark.xfailmarker once the fix made the test pass.ApplyTestmethods and the separateApplyCompilationTestclass into a single data-driventest_autotag_itemstest, reducing noise and improving coverage clarity.test/autotag/to better reflect module structure.