Skip to content

Make InQuery hashable when its pattern is a list#6838

Merged
snejus merged 1 commit into
beetbox:masterfrom
valentynkit:fix/inquery-unhashable-pattern
Jul 15, 2026
Merged

Make InQuery hashable when its pattern is a list#6838
snejus merged 1 commit into
beetbox:masterfrom
valentynkit:fix/inquery-unhashable-pattern

Conversation

@valentynkit

Copy link
Copy Markdown
Contributor

Fixes #5354.

beet splupdate raises TypeError: unhashable type: 'list' whenever a smartplaylist configuration contains a playlist: query. smartplaylist collects playlists in a set, which hashes the query. playlist: parses to PlaylistQuery, a subclass of InQuery whose pattern is a list, and InQuery inherited FieldQuery.__hash__, which does hash(self.pattern) and fails on a list.

As @wisp3rwind suggested on the issue, this overrides __hash__ on InQuery to hash a tuple copy of the pattern. It stays order-sensitive to match the inherited FieldQuery.__eq__, so the hash/eq contract holds.

Changes:

  • beets/dbcore/query.py: add InQuery.__hash__.
  • test/dbcore/test_query.py: regression test that an InQuery with a list pattern can be put in a set.
  • changelog entry under Bug fixes.

Left the order-insensitive __eq__/__hash__ and the smartplaylist set-vs-dict cleanup you also floated out of scope here; happy to follow up on either if you want them.

@valentynkit
valentynkit requested a review from a team as a code owner July 14, 2026 19:44
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.91%. Comparing base (35e4811) to head (eb7c832).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6838   +/-   ##
=======================================
  Coverage   74.91%   74.91%           
=======================================
  Files         163      163           
  Lines       21172    21174    +2     
  Branches     3341     3341           
=======================================
+ Hits        15860    15862    +2     
  Misses       4545     4545           
  Partials      767      767           
Files with missing lines Coverage Δ
beets/dbcore/query.py 90.90% <100.00%> (+0.04%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snejus snejus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks!

InQuery inherited FieldQuery.__hash__, which hashes the pattern directly.
A list pattern raises `unhashable type: 'list'`, which broke the
smartplaylist `splupdate` command whenever a `playlist:` query was configured.
@snejus
snejus force-pushed the fix/inquery-unhashable-pattern branch from e64c918 to eb7c832 Compare July 15, 2026 07:02
@snejus
snejus enabled auto-merge July 15, 2026 07:02
@snejus
snejus merged commit 4775599 into beetbox:master Jul 15, 2026
16 checks passed
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.

In 2.0.0 (from git snapshot), running 'beet splupdate' (for smartplaylist) fails with TypeError whenever 'playlist:x' is in any query

2 participants