mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
plugins/web: fix endpoints /…/values/…
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.
This commit is contained in:
parent
07445fdd07
commit
666c412b0e
3 changed files with 12 additions and 1 deletions
|
|
@ -232,7 +232,7 @@ def _get_unique_table_field_values(model, field, sort_field):
|
||||||
raise KeyError
|
raise KeyError
|
||||||
with g.lib.transaction() as tx:
|
with g.lib.transaction() as tx:
|
||||||
rows = tx.query(
|
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]
|
return [row[0] for row in rows]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@ Bug fixes:
|
||||||
accepted a list of strings). :bug:`5962`
|
accepted a list of strings). :bug:`5962`
|
||||||
- Fix a bug introduced in release 2.4.0 where import from any valid
|
- 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.
|
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:
|
For plugin developers:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,13 @@ class WebPluginTest(ItemInDBTestCase):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert len(res_json["items"]) == 3
|
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):
|
def test_get_single_item_by_id(self):
|
||||||
response = self.client.get("/item/1")
|
response = self.client.get("/item/1")
|
||||||
res_json = json.loads(response.data.decode("utf-8"))
|
res_json = json.loads(response.data.decode("utf-8"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue