Skip to content

ui: remove do_query to tighten input_select_objects - #6942

Open
snejus wants to merge 3 commits into
type-beets-corefrom
remove-do-query
Open

ui: remove do_query to tighten input_select_objects#6942
snejus wants to merge 3 commits into
type-beets-corefrom
remove-do-query

Conversation

@snejus

@snejus snejus commented Aug 18, 2026

Copy link
Copy Markdown
Member

Part of #6924.

  • Purpose

    • Fix interactive selection in modify so chosen objects are actually applied correctly.
    • Simplify command flow by removing the shared do_query helper and letting each command handle item and album queries directly.
  • Architecture

    • beets.ui.commands.utils.do_query is removed.
    • Query and selection logic is now pushed into each command module: modify, move, remove, update, write, and edit.
    • Common command behavior is still shared where it helps, but around concrete item/album operations instead of a generic query abstraction.
    • ui.input_select_objects now has a narrower, model-specific type signature based on AlbumOrItem, which makes its return value clearer and easier to use safely.
  • High-level impact

    • Fixes a user-facing bug in modify interactive select mode.
    • Reduces hidden coupling between commands and a central query helper.
    • Makes command behavior easier to follow: each command now fetches and filters exactly the objects it operates on.
    • Improves typing and prepares the command layer for safer future refactors with less ambiguity around item vs album handling.
  • Tests and docs

    • Tests were updated to match the new command structure, especially for move, remove, and update.
    • docs/changelog.rst documents the modify selection bug fix.

Copilot AI lite review requested due to automatic review settings August 18, 2026 18:57
@snejus
snejus requested a review from a team as a code owner August 18, 2026 18:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

grug see PR want fix interactive select bug in modify, and also kill do_query so each command do own query work. grug like less hidden helper, but grug see some new typing + prompt bugs that will make CI sad (mypy/ruff).

Changes:

  • Remove shared beets.ui.commands.utils.do_query helper and adjust commands/tests to query items/albums directly.
  • Fix modify confirm-selection flow to use ui.show_model_changes so chosen objects get applied right.
  • Tighten/adjust ui.input_select_objects typing and update command modules (move, remove, update, write, edit) to new flow.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/ui/commands/test_utils.py Remove tests tied to deleted do_query.
test/ui/commands/test_update.py Update tests for new update_items(items=...) API.
test/ui/commands/test_remove.py Split tests between remove_items and new remove_albums.
test/ui/commands/test_move.py Update tests for move_items vs move_albums APIs and dest encoding.
docs/changelog.rst Document modify interactive select bug fix.
beetsplug/edit.py Stop using do_query; query items/albums directly.
beets/ui/commands/write.py Stop using do_query; iterate lib.items(query).
beets/ui/commands/utils.py Delete do_query helper module.
beets/ui/commands/update.py Refactor update_items to accept explicit items iterable; query done in update_func.
beets/ui/commands/remove.py Refactor into remove_objects + remove_items/remove_albums.
beets/ui/commands/move.py Refactor into move_objects + move_items/move_albums, remove do_query.
beets/ui/commands/modify.py Refactor into modify_objects + modify_items/modify_albums; fix selection apply bug.
beets/ui/init.py Narrow (then adjust) typing for input_select_objects return/args.
Suppressed comments (4)

beets/ui/commands/remove.py:37

  • grug see prompt text use len(objs) for item count. when objs be albums, count wrong. grug say remove count so prompt not lie.
        else:
            fmt = ""
            prompt = "Really remove from the library?"
            prompt_all = (
                f"Really remove {len(objs)} item{suffix} from the library?"

beets/ui/commands/move.py:79

  • grug see num_unmoved math always zero: num_objs == len(objs), so num_unmoved always 0. message code dead, confuse future grug.
    num_objs = len(objs)
    num_unmoved = num_objs - len(objs)
    # Report unmoved files that match the query.
    unmoved_msg = ""
    if num_unmoved > 0:

beets/ui/commands/update.py:29

  • grug see update_items fields arg can be None (opts.fields default None) but type say list[str]. mypy will bonk. make it Optional.
    items: Iterable[Item],
    move: bool,
    pretend: bool,
    fields: list[str],
    exclude_fields: list[str] | None = None,

beets/ui/commands/modify.py:127

  • grug see same doc string typo again: "pairse" -> "pairs".
    """Modifies matching items according to user-specified assignments and
    deletions.

    `mods` is a dictionary of field and value pairse indicating
    assignments. `dels` is a list of fields to be deleted.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread beets/ui/commands/remove.py Outdated
Comment thread beets/ui/commands/move.py Outdated
Comment thread beets/ui/__init__.py Outdated
Comment thread beets/ui/__init__.py Outdated
Comment thread beets/ui/commands/move.py Outdated
Comment thread beets/ui/commands/move.py Outdated
Comment thread beets/ui/commands/modify.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 25 out of 25 changed files in this pull request and generated no new comments.

Suppressed comments (4)

beets/ui/commands/remove.py:42

  • grug see remove prompt text wrong: say "item" even when removing albums, no plural "items", and has trailing "?" so input_select_objects make "??". grug say build noun + plural, and do not include '?' in prompt strings.
            fmt = ""
            prompt = "Really remove from the library?"
            prompt_all = (
                f"Really remove {len(objs)} item{album_str} from the library?"
            )

beets/ui/commands/move.py:80

  • grug see num_unmoved math always make 0 (len(objs) - len(objs)). log say "already in place" count but never true. grug say either pass real unmoved count from caller, or do not try compute here.
    num_objs = len(objs)
    num_unmoved = num_objs - len(objs)

beets/ui/commands/remove.py:21

  • grug see type here too loose: remove_objects take Callable[[str, AlbumOrItem], None] but callers pass fmt_item (Item only) or fmt_album (Album only). static type checker can yell. grug say make remove_objects generic over same T for objs and formatter.

This issue also appears on line 38 of the same file.

def remove_objects(
    objs: Sequence[AlbumOrItem],
    fmt_obj: Callable[[str, AlbumOrItem], None],
    file_count: int,
    album_str: str,

beets/ui/commands/update.py:28

  • grug see update_items say fields: list[str], but code + option parser pass None when no --field. type lie make checker sad. grug say annotate as optional.
    fields: list[str],

@snejus
snejus force-pushed the remove-do-query branch 2 times, most recently from bff3c92 to f03dbdf Compare August 18, 2026 22:17
@snejus
snejus requested a review from JOJ0 as a code owner August 19, 2026 01:52
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.76923% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (type-beets-core@2d687de). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beets/ui/commands/move.py 85.00% 3 Missing ⚠️
beets/ui/commands/update.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             type-beets-core    #6942   +/-   ##
==================================================
  Coverage                   ?   76.02%           
==================================================
  Files                      ?      164           
  Lines                      ?    21560           
  Branches                   ?     3334           
==================================================
  Hits                       ?    16390           
  Misses                     ?     4380           
  Partials                   ?      790           
Files with missing lines Coverage Δ
beets/ui/__init__.py 82.75% <ø> (ø)
beets/ui/commands/modify.py 95.87% <100.00%> (ø)
beets/ui/commands/remove.py 100.00% <100.00%> (ø)
beets/ui/commands/write.py 79.31% <100.00%> (ø)
beetsplug/edit.py 79.06% <100.00%> (ø)
beets/ui/commands/move.py 76.82% <85.00%> (ø)
beets/ui/commands/update.py 76.04% <0.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@semohr semohr changed the title core: remove do_query to tighten input_select_objects ui: remove do_query to tighten input_select_objects Aug 19, 2026
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