Skip to content

Commit

Permalink
Merge pull request ckan#8210 from ckan/8207-org-list-error
Browse files Browse the repository at this point in the history
[ckan#8207] Fix exception in `group_list` / `organization_list` when passing the `groups` / `organizations`
  • Loading branch information
wardi authored Jun 26, 2024
2 parents ef91cb4 + 76f6fba commit da62ed6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/8210.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix exception in ``group_list`` / ``organization_list`` when passing the ``groups`` / ``organizations`` parameters
3 changes: 2 additions & 1 deletion ckan/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions ckan/tests/logic/action/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit da62ed6

Please sign in to comment.