From 666c412b0ee91b25b08757bc28bbffd0fd249b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Tue, 11 Nov 2025 21:04:30 +0100 Subject: [PATCH] =?UTF-8?q?plugins/web:=20fix=20endpoints=20`/=E2=80=A6/va?= =?UTF-8?q?lues/=E2=80=A6`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following #4709 and #5447, the web plugin used single-quotes (ie. string litteral) in the SQL query for table columns. Thus, for instance, the query `GET /item/values/albumartist` would return the litteral "albumartist" instead of a list of unique album artists. --- beetsplug/web/__init__.py | 2 +- docs/changelog.rst | 4 ++++ test/plugins/test_web.py | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/beetsplug/web/__init__.py b/beetsplug/web/__init__.py index 7b13cf016..1fbb3b0f3 100644 --- a/beetsplug/web/__init__.py +++ b/beetsplug/web/__init__.py @@ -232,7 +232,7 @@ def _get_unique_table_field_values(model, field, sort_field): raise KeyError with g.lib.transaction() as tx: rows = tx.query( - f"SELECT DISTINCT '{field}' FROM '{model._table}' ORDER BY '{sort_field}'" + f"SELECT DISTINCT {field} FROM {model._table} ORDER BY {sort_field}" ) return [row[0] for row in rows] diff --git a/docs/changelog.rst b/docs/changelog.rst index 366af9ff0..c5a0dab53 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -43,6 +43,10 @@ Bug fixes: accepted a list of strings). :bug:`5962` - Fix a bug introduced in release 2.4.0 where import from any valid import-log-file always threw a "none of the paths are importable" error. +- :doc:`/plugins/web`: repair broken `/item/values/…` and `/albums/values/…` + endpoints. Previously, due to single-quotes (ie. string literal) in the SQL + query, the query eg. `GET /item/values/albumartist` would return the literal + "albumartist" instead of a list of unique album artists. For plugin developers: diff --git a/test/plugins/test_web.py b/test/plugins/test_web.py index 9fc3d109d..4a532e02c 100644 --- a/test/plugins/test_web.py +++ b/test/plugins/test_web.py @@ -118,6 +118,13 @@ class WebPluginTest(ItemInDBTestCase): assert response.status_code == 200 assert len(res_json["items"]) == 3 + def test_get_unique_item_artist(self): + response = self.client.get("/item/values/artist") + res_json = json.loads(response.data.decode("utf-8")) + + assert response.status_code == 200 + assert res_json["values"] == ["", "AAA Singers"] + def test_get_single_item_by_id(self): response = self.client.get("/item/1") res_json = json.loads(response.data.decode("utf-8"))