Skip to content

Handle legacy fields in modify and queries#6494

Merged
snejus merged 2 commits intomasterfrom
handle-legacy-fields-in-modify
Apr 7, 2026
Merged

Handle legacy fields in modify and queries#6494
snejus merged 2 commits intomasterfrom
handle-legacy-fields-in-modify

Conversation

@snejus
Copy link
Copy Markdown
Member

@snejus snejus commented Apr 3, 2026

Handle legacy singular field names in modify and queries

This PR centralises the mapping of legacy singular field names (e.g. genre, composer, lyricist, remixer, arranger) to their modern plural multi-valued equivalents (e.g. genres, composers, ...) and applies that rewrite in two places: the modify command and library field queries.

What changed

beets/util/deprecation.py — new source of truth

Two module-level dicts, ALBUM_LEGACY_TO_LIST_FIELD and ITEM_LEGACY_TO_LIST_FIELD, now live here. A new helper maybe_replace_legacy_field(field, is_album) wraps the lookup, emits a deprecation warning via the shared log, and returns the canonical field name.

beets/library/models.py — queries now handle legacy fields

field_query calls maybe_replace_legacy_field before resolving whether the field is fast or slow. This means queries like genre::rock or composer::bach are transparently rewritten and warn the user.

beets/ui/commands/modify.py — simplified using the shared helper

The inline legacy-field lookup and deprecate_for_user call inside modify_parse_args are replaced with a single call to maybe_replace_legacy_field. The is_album parameter is passed through from modify_func.

beets/autotag/hooks.pyLEGACY_TO_LIST_FIELD now references the shared dicts

AlbumInfo and TrackInfo no longer define their own inline mappings; they reference the canonical dicts from deprecation.py.

Impact

  • Users who pass legacy field names in modify assignments or in query expressions now get a deprecation warning and correct behaviour, instead of silently operating on a non-existent field.
  • The legacy mapping is defined once, removing the previous drift risk between hooks.py, modify.py, and any future call sites.
  • Fixes 🐛6483.

@snejus snejus requested a review from a team as a code owner April 3, 2026 17:46
@snejus snejus linked an issue Apr 3, 2026 that may be closed by this pull request
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from da2d4bb to b41d349 Compare April 3, 2026 17:49
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.18%. Comparing base (4aaf58b) to head (724891f).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6494      +/-   ##
==========================================
+ Coverage   70.15%   70.18%   +0.02%     
==========================================
  Files         147      147              
  Lines       18662    18680      +18     
  Branches     3040     3042       +2     
==========================================
+ Hits        13093    13111      +18     
  Misses       4927     4927              
  Partials      642      642              
Files with missing lines Coverage Δ
beets/autotag/hooks.py 98.85% <100.00%> (+<0.01%) ⬆️
beets/library/models.py 87.10% <100.00%> (+0.04%) ⬆️
beets/ui/commands/modify.py 93.93% <100.00%> (+0.18%) ⬆️
beets/util/deprecation.py 91.17% <100.00%> (+5.46%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snejus snejus force-pushed the use-multi-value-remixers branch from 85969e8 to c77ea75 Compare April 3, 2026 17:56
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from b41d349 to 13f48d1 Compare April 3, 2026 17:57
@snejus snejus force-pushed the use-multi-value-remixers branch from c77ea75 to a95fea1 Compare April 3, 2026 18:13
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from 13f48d1 to 6eb483c Compare April 3, 2026 18:13
@snejus snejus requested a review from Copilot April 3, 2026 21:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

PR make beet modify accept old singular multi-value field names, then rewrite to new plural field names and warn user, so user no longer make wrong custom field by accident.

Changes:

  • Add central legacy->plural list field maps in beets/util/deprecation.py
  • Reuse those maps from autotag AlbumInfo / TrackInfo instead of inline maps
  • Update modify_parse_args to rewrite legacy assignment keys + emit user-facing deprecation warning; add tests + docs

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
beets/util/deprecation.py Add shared legacy singular → plural list-field mapping constants.
beets/autotag/hooks.py Switch Info subclasses to use shared mapping constants.
beets/ui/commands/modify.py Rewrite legacy assignment keys to plural fields + warn user.
test/ui/commands/test_modify.py Update call sites for new arg + add rewrite/warn tests.
test/autotag/test_hooks.py Stop using Info directly in legacy-field tests; use TrackInfo.
docs/reference/cli.rst Document legacy singular field support in modify.
docs/changelog.rst Add changelog entry for modify legacy-field rewrite behavior.

@snejus snejus force-pushed the use-multi-value-remixers branch from a95fea1 to 753c398 Compare April 3, 2026 21:59
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from 6eb483c to 43e4469 Compare April 3, 2026 21:59
@snejus snejus force-pushed the use-multi-value-remixers branch from 753c398 to 809cbca Compare April 3, 2026 22:05
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from 43e4469 to b5a59b5 Compare April 3, 2026 22:05
@JOJ0 JOJ0 added the core Pull requests that modify the beets core `beets` label Apr 4, 2026
@snejus snejus force-pushed the use-multi-value-remixers branch from 809cbca to 392962e Compare April 4, 2026 12:27
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from b5a59b5 to 2427ad7 Compare April 4, 2026 12:31
@snejus snejus force-pushed the use-multi-value-remixers branch 3 times, most recently from 8997fa5 to 8c57b87 Compare April 5, 2026 08:15
Base automatically changed from use-multi-value-remixers to master April 5, 2026 08:21
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch 3 times, most recently from 66977cf to 081f42b Compare April 7, 2026 01:25
@snejus snejus changed the title Handle legacy fields in modify Handle legacy fields in modify and queries Apr 7, 2026
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from 081f42b to 02393c9 Compare April 7, 2026 01:33
@snejus snejus requested a review from Copilot April 7, 2026 08:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

@snejus snejus force-pushed the handle-legacy-fields-in-modify branch 3 times, most recently from 4f5331a to de3054f Compare April 7, 2026 09:18
@snejus snejus force-pushed the handle-legacy-fields-in-modify branch from de3054f to 724891f Compare April 7, 2026 09:43
@snejus snejus merged commit 137c049 into master Apr 7, 2026
20 checks passed
@snejus snejus deleted the handle-legacy-fields-in-modify branch April 7, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Pull requests that modify the beets core `beets`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modifying "genre" instead of "genres" fails silently

3 participants