Skip to content

Commit f3552f0

Browse files
authored
Merge pull request #4140 from jcassette/aunique-flexattr
Use slow queries for flexible attributes in aunique (fix #2678, close #3553)
2 parents 3b53181 + b67c25a commit f3552f0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

beets/library.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,9 @@ def tmpl_aunique(self, keys=None, disam=None, bracket=None):
16901690
subqueries = []
16911691
for key in keys:
16921692
value = album.get(key, '')
1693-
subqueries.append(dbcore.MatchQuery(key, value))
1693+
# Use slow queries for flexible attributes.
1694+
fast = key in album.item_keys
1695+
subqueries.append(dbcore.MatchQuery(key, value, fast))
16941696
albums = self.lib.albums(dbcore.AndQuery(subqueries))
16951697

16961698
# If there's only one album to matching these details, then do

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Bug fixes:
7070

7171
* :doc:`/plugins/export`: Fix duplicated output.
7272

73+
* :doc:`/dev/library`: Use slow queries for flexible attributes in aunique.
74+
:bug:`2678` :bug:`3553`
75+
7376
1.5.0 (August 19, 2021)
7477
-----------------------
7578

test/test_library.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,16 @@ def test_remove_brackets(self):
791791
self._setf('foo%aunique{albumartist album,year,}/$title')
792792
self._assert_dest(b'/base/foo 2001/the title', self.i1)
793793

794+
def test_key_flexible_attribute(self):
795+
album1 = self.lib.get_album(self.i1)
796+
album1.flex = 'flex1'
797+
album2 = self.lib.get_album(self.i2)
798+
album2.flex = 'flex2'
799+
album1.store()
800+
album2.store()
801+
self._setf('foo%aunique{albumartist album flex,year}/$title')
802+
self._assert_dest(b'/base/foo/the title', self.i1)
803+
794804

795805
class PluginDestinationTest(_common.TestCase):
796806
def setUp(self):

0 commit comments

Comments
 (0)