Skip to content

Conversation

@a544jh
Copy link

@a544jh a544jh commented Jan 10, 2026

Description

Note: This fix was developed with assistance from Claude Code (AI). The problem was identified by me, and Claude helped investigate the codebase, trace the git history to find the original FIXME, implement the fix, and update the tests. All changes have been reviewed and tested.

When importing with autotag: no, duplicate detection is completely bypassed. The import_asis stage calls _apply_choice() directly without first calling _resolve_duplicates(), meaning any configured duplicate_keys and duplicate_action settings are ignored.

This was a known limitation. Commit 79d1203 (Sep 2014) added a FIXME comment:

# FIXME We should also resolve duplicates when not
# autotagging. This is currently handled in `user_query`

The FIXME was removed during a comment cleanup in f145e3b (Jan 2015), but the underlying issue was never fixed. A test test_no_autotag_keeps_duplicate_album was added to document the existing behavior at the time.

The Fix

Add _resolve_duplicates(session, task) to the import_asis stage before _apply_choice(), matching the behavior of the user_query stage used when autotagging.

Test Changes

  • Renamed test_no_autotag_keeps_duplicate_albumtest_no_autotag_removes_duplicate_album
  • Fixed the test to use album metadata instead of item metadata for duplicate matching
  • Added missing import_file.save() call

To Do

  • Documentation (Bugfix for existing documented config options)
  • Changelog
  • Tests

@a544jh a544jh requested a review from a team as a code owner January 10, 2026 18:44
@github-actions
Copy link

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.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Calling _resolve_duplicates(session, task) from import_asis changes behavior for all ASIS imports, including singletons; it’s worth double-checking that _resolve_duplicates behaves correctly for single-item tasks (and not only album imports) and that this new behavior is intentional for those cases.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Calling `_resolve_duplicates(session, task)` from `import_asis` changes behavior for all ASIS imports, including singletons; it’s worth double-checking that `_resolve_duplicates` behaves correctly for single-item tasks (and not only album imports) and that this new behavior is intentional for those cases.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.70%. Comparing base (c04fc95) to head (b21c231).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6280   +/-   ##
=======================================
  Coverage   68.70%   68.70%           
=======================================
  Files         138      138           
  Lines       18537    18538    +1     
  Branches     3063     3063           
=======================================
+ Hits        12736    12737    +1     
  Misses       5148     5148           
  Partials      653      653           
Files with missing lines Coverage Δ
beets/importer/stages.py 88.12% <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.

When importing with autotag=no, duplicate detection was skipped entirely
because the import_asis stage called _apply_choice() directly without
first calling _resolve_duplicates(). This meant the duplicate_keys and
duplicate_action config options were ignored for as-is imports.

This was a known limitation documented by a FIXME comment added in
commit 79d1203 (Sep 2014): "We should also resolve duplicates when
not autotagging." The FIXME was later removed during a comment cleanup
(f145e3b) but the issue was never addressed.

This commit adds the _resolve_duplicates() call to import_asis, ensuring
duplicate detection works consistently regardless of the autotag setting.
This applies to both album imports and singleton imports.

Test changes:
- Renamed test_no_autotag_keeps_duplicate_album to
  test_no_autotag_removes_duplicate_album to verify the corrected behavior
- Added test_no_autotag_removes_duplicate_singleton to verify singleton
  duplicate detection also works with autotag=no

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@a544jh a544jh force-pushed the fix-duplicate-detection-asis branch from d77142c to b21c231 Compare January 10, 2026 18:53
@JOJ0 JOJ0 added the core Pull requests that modify the beets core `beets` label Jan 10, 2026
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.

2 participants