Support multi-valued fields in rewrite and advancedrewrite plugins#6518
Merged
Support multi-valued fields in rewrite and advancedrewrite plugins#6518
Conversation
6377a8d to
619f7e8
Compare
619f7e8 to
e21f56f
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds proper rewrite support for multi-valued (list) fields in the rewrite and advancedrewrite plugins so rules can affect fields like genres instead of being ignored.
Changes:
- Introduce
apply_rewrite_rules/rewrite_valueinbeetsplug/rewrite.pyto handlestrandlistvalues. - Delegate
advancedrewritesimple-rule rewriting to the shared helper. - Add tests + docs + changelog entry covering list-field rewriting behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
beetsplug/rewrite.py |
Adds singledispatch-based rewrite helper for scalar + list values; used by template field rewriters. |
beetsplug/advancedrewrite.py |
Switches simple-rule path to call shared helper before advanced-query rewrites. |
test/plugins/test_rewrite.py |
New tests for scalar rewriting, rule order, and list-field (genres) rewriting. |
test/plugins/test_advancedrewrite.py |
Adds coverage for simple-rule rewriting on list fields. |
docs/plugins/rewrite.rst |
Documents that rewrite rules apply to matching list entries for multi-valued fields. |
docs/plugins/advancedrewrite.rst |
Notes parity with rewrite for list-field simple rules. |
docs/changelog.rst |
Adds bugfix note for multi-valued rewrite behavior. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6518 +/- ##
==========================================
+ Coverage 70.40% 70.55% +0.15%
==========================================
Files 148 148
Lines 18806 18820 +14
Branches 3067 3066 -1
==========================================
+ Hits 13240 13279 +39
+ Misses 4916 4894 -22
+ Partials 650 647 -3
🚀 New features to boost your workflow:
|
930714a to
2ff7887
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix rewriting of multi-valued fields (
rewrite/advancedrewriteplugins)Bug: Both
rewriteandadvancedrewriteplugins assumed all field values are scalars, so list-type fields (e.g.genres) were not rewritten correctly. Additionally, only the first matching rule was ever applied to a field.What changed
Core logic (
beetsplug/rewrite.py):rewrite_valuesingledispatchfunction to handle bothstrandlist[str]values. For lists, each element is rewritten individually.apply_rewrite_rulesas a shared utility — now applies all matching rules in config order (previously stopped at the first match).advancedrewriteplugin:apply_rewrite_rules, fixing list field support there too.Behaviour change — rule application order:
Previously, only the first matching rule was applied. Now, all rules run in config order, allowing chained rewrites. For example:
This now produces
"Experience catalog"instead of"hendrix catalog".Fixes: #6515