From 1c64b8be32a6ba4db5cd3da33ec5f7aad5e67784 Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Sat, 29 Mar 2025 13:07:41 +0100 Subject: [PATCH 1/3] Convert flexible field values to SQL before storing them This is required to support multivalued fields as flexible fields. --- beets/dbcore/db.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index b780c5756..a569feba7 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -607,6 +607,7 @@ class Model(ABC, Generic[D]): for key, value in self._values_flex.items(): if key in self._dirty: self._dirty.remove(key) + value = self._type(key).to_sql(value) tx.mutate( "INSERT INTO {} " "(entity_id, key, value) " From 55ef006b3e6908d05a1c158550c7b273008e3ea8 Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Sun, 29 Jun 2025 12:45:15 +0200 Subject: [PATCH 2/3] Add changelog entry --- docs/changelog.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 7fb81237e..c2b0c0ca5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -76,7 +76,11 @@ For plugin developers: ``album_for_id``, ``candidates``, ``item_candidates``, ``album_distance``, ``track_distance`` methods, please update your plugin to inherit from the new baseclass, as otherwise your plugin will stop working with the next major release. - +* Flexible fields, which can be used by plugins to store additional metadata, + now also support list values. Previously, beets would throw an error while + storing the data in the SQL database due to missing type conversion. + :bug:`5698` + Other changes: * Refactor: Split responsibilities of Plugins into MetaDataPlugins and general Plugins. From 8db661b115044ccdd9ccb51c8662a8f7f8b1d513 Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Wed, 16 Jul 2025 21:41:29 +0200 Subject: [PATCH 3/3] Add test --- test/test_plugins.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_plugins.py b/test/test_plugins.py index 207522430..d9da17e61 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -94,6 +94,20 @@ class ItemTypesTest(PluginLoaderTestCase): out = self.run_with_output("ls", "rating:3..5") assert "aaa" not in out + def test_multi_value_flex_field_type(self): + class MultiValuePlugin(plugins.BeetsPlugin): + item_types = {"multi_value": types.MULTI_VALUE_DSV} + + self.register_plugin(MultiValuePlugin) + + item = Item(path="apath", artist="aaa") + item.multi_value = ["one", "two", "three"] + item.add(self.lib) + + out = self.run_with_output("ls", "-f", "$multi_value") + delimiter = types.MULTI_VALUE_DSV.delimiter + assert out == f"one{delimiter}two{delimiter}three\n" + class ItemWriteTest(PluginLoaderTestCase): def setUp(self):