diff --git a/beets/library.py b/beets/library.py index df1b8ffee5..d35a7fae6b 100644 --- a/beets/library.py +++ b/beets/library.py @@ -1690,7 +1690,9 @@ def tmpl_aunique(self, keys=None, disam=None, bracket=None): subqueries = [] for key in keys: value = album.get(key, '') - subqueries.append(dbcore.MatchQuery(key, value)) + # Use slow queries for flexible attributes. + fast = key in album.item_keys + subqueries.append(dbcore.MatchQuery(key, value, fast)) albums = self.lib.albums(dbcore.AndQuery(subqueries)) # If there's only one album to matching these details, then do diff --git a/docs/changelog.rst b/docs/changelog.rst index 1b4590f94c..552cdc31fc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -70,6 +70,9 @@ Bug fixes: * :doc:`/plugins/export`: Fix duplicated output. +* :doc:`/dev/library`: Use slow queries for flexible attributes in aunique. + :bug:`2678` :bug:`3553` + 1.5.0 (August 19, 2021) ----------------------- diff --git a/test/test_library.py b/test/test_library.py index e64f755610..da7d745e29 100644 --- a/test/test_library.py +++ b/test/test_library.py @@ -791,6 +791,16 @@ def test_remove_brackets(self): self._setf('foo%aunique{albumartist album,year,}/$title') self._assert_dest(b'/base/foo 2001/the title', self.i1) + def test_key_flexible_attribute(self): + album1 = self.lib.get_album(self.i1) + album1.flex = 'flex1' + album2 = self.lib.get_album(self.i2) + album2.flex = 'flex2' + album1.store() + album2.store() + self._setf('foo%aunique{albumartist album flex,year}/$title') + self._assert_dest(b'/base/foo/the title', self.i1) + class PluginDestinationTest(_common.TestCase): def setUp(self):