diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index d55cf70cd..81c1be4b9 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -605,6 +605,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) " diff --git a/docs/changelog.rst b/docs/changelog.rst index f02a3c159..ab896a7ff 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -101,6 +101,10 @@ For plugin developers: - ``plugins.load_plugins`` function does not anymore accept the list of plugins to load. Instead, it loads all plugins that are configured by :ref:`plugins-config` configuration. +- 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: diff --git a/test/test_plugins.py b/test/test_plugins.py index a5e031e66..df338f924 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -46,7 +46,10 @@ from beets.util import displayable_path, syspath class TestPluginRegistration(PluginTestCase): class RatingPlugin(plugins.BeetsPlugin): - item_types = {"rating": types.Float()} + item_types = { + "rating": types.Float(), + "multi_value": types.MULTI_VALUE_DSV, + } def __init__(self): super().__init__() @@ -83,6 +86,15 @@ class TestPluginRegistration(PluginTestCase): assert MediaFile(syspath(item.path)).artist == "YYY" + def test_multi_value_flex_field_type(self): + 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 PluginImportTestCase(ImportHelper, PluginTestCase): def setUp(self):