Skip to content

Commit

Permalink
fix(filters): fix search filter when used in collection (#1392)
Browse files Browse the repository at this point in the history
Using the search filter in the filter collection resulted in an error
where the filter did not have a model. This was caused because the
class method `filterset.get_filters()` was used instead of the properly
initialized `filterset.filters` where the model was properly set.
  • Loading branch information
Jonas Metzener authored Feb 25, 2021
1 parent 3b600e2 commit d99db68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions caluma/caluma_core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def filter(self, qs, value):
invert = flt.pop("invert", False)
flt_key = list(flt.keys())[0]
flt_val = flt[flt_key]
filter = filter_coll.get_filters()[flt_key]
filter = filter_coll.filters[flt_key]

new_qs = filter.filter(qs, flt_val)

Expand All @@ -99,7 +99,7 @@ def _order_part(self, qs, ord, filter_coll):

assert len(ord) == 1
filt_name = list(ord.keys())[0]
filter = filter_coll.get_filters()[filt_name]
filter = filter_coll.filters[filt_name]
qs, field = filter.get_ordering_value(qs, ord[filt_name])

# Normally, people use ascending order, and in this context it seems
Expand Down
23 changes: 23 additions & 0 deletions caluma/caluma_core/tests/test_search_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def test_search_in_filter_collection(db, schema_executor, form_factory):
form_factory(name="Test 1")
form_factory(name="Test 2")
form_factory(name="Test 3")

query = """
query($search: String!) {
allForms(filter: [{ search: $search }]) {
edges {
node {
slug
name
}
}
}
}
"""

result = schema_executor(query, variable_values={"search": "Test 2"})
assert not result.errors

assert len(result.data["allForms"]["edges"]) == 1
assert result.data["allForms"]["edges"][0]["node"]["name"] == "Test 2"

0 comments on commit d99db68

Please sign in to comment.