diff --git a/changes/8210.bugfix b/changes/8210.bugfix new file mode 100644 index 00000000000..6b8f19aaeb4 --- /dev/null +++ b/changes/8210.bugfix @@ -0,0 +1 @@ +Fix exception in ``group_list`` / ``organization_list`` when passing the ``groups`` / ``organizations`` parameters diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index 73433d35761..80f2b1032e6 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -10,7 +10,7 @@ from typing import (Container, Optional, Union, Any, cast, Type) -from ckan.common import config, asbool +from ckan.common import config, asbool, aslist import sqlalchemy from sqlalchemy import text @@ -387,6 +387,7 @@ def _group_or_org_list( query = query.filter(model.Group.state == 'active') if groups: + groups = aslist(groups, sep=",") query = query.filter(model.Group.name.in_(groups)) if q: q = u'%{0}%'.format(q) diff --git a/ckan/tests/logic/action/test_get.py b/ckan/tests/logic/action/test_get.py index c6072378dd4..d384a5b0d3c 100644 --- a/ckan/tests/logic/action/test_get.py +++ b/ckan/tests/logic/action/test_get.py @@ -473,6 +473,19 @@ def test_group_list_wrong_offset(self): with pytest.raises(logic.ValidationError): helpers.call_action("group_list", offset="-2") + @pytest.mark.parametrize("value", ["bb,cc", ["bb", "cc"]]) + def test_group_list_filter_by_name(self, value): + + factories.Group(name="aa") + factories.Group(name="bb") + factories.Group(name="cc") + + group_list = helpers.call_action("group_list", groups=value, sort="name asc") + + assert len(group_list) == 2 + assert group_list[0] == "bb" + assert group_list[1] == "cc" + @pytest.mark.usefixtures("clean_db", "clean_index") class TestGroupShow(object):