Convert flexible field values to SQL before storing them (#5833)

## Description

This is required to support list values in flexible fields.
See #5698 for more details.
This commit is contained in:
Šarūnas Nejus 2025-08-19 13:44:27 +01:00 committed by GitHub
commit b7091bf120
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View file

@ -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) "

View file

@ -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:

View file

@ -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):