Skip to content

[ENG-8052] Fixed FilterMixin issue with multiple values of any filter #11150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/base/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class FilterMixin:
LIST_FIELDS = (ser.ListField,)
RELATIONSHIP_FIELDS = (RelationshipField, TargetField)

MULTIPLE_VALUES_FIELDS = ['_id', 'guid._id', 'journal_id', 'moderation_state', 'event_name']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self.serializer_class:
Expand Down Expand Up @@ -292,7 +294,7 @@ def parse_query_params(self, query_params):
query.get(key).update({
field_name: self._parse_date_param(field, source_field_name, op, value),
})
elif not isinstance(value, int) and source_field_name in ['_id', 'guid._id', 'journal_id', 'moderation_state']:
elif not isinstance(value, int) and source_field_name in self.MULTIPLE_VALUES_FIELDS:
query.get(key).update({
field_name: {
'op': 'in',
Expand Down
6 changes: 6 additions & 0 deletions api_tests/subscriptions/views/test_subscriptions_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ def test_cannot_post_patch_put_or_delete(self, app, url, user):
assert patch_res.status_code == 405
assert put_res.status_code == 405
assert delete_res.status_code == 405

def test_multiple_values_filter(self, app, url, global_user_notification, user):
res = app.get(url + '?filter[event_name]=comments,global', auth=user.auth)
assert len(res.json['data']) == 2
for subscription in res.json['data']:
subscription['attributes']['event_name'] in ['global', 'comments']
Loading