Skip to content

Commit

Permalink
Make sure F({'and': []}) works
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed Jun 9, 2015
1 parent ab99a82 commit d677bd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion elasticsearch_dsl/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def F(name_or_filter='match_all', filters=None, **params):
raise ValueError('F() can only accept dict with a single filter ({"bool": {...}}). '
'Instead it got (%r)' % name_or_filter)
name, params = name_or_filter.copy().popitem()
return Filter.get_dsl_class(name)(**params)
if isinstance(params, dict):
return Filter.get_dsl_class(name)(**params)
else:
# and filter can have list
return Filter.get_dsl_class(name)(params)

# Term(...)
if isinstance(name_or_filter, Filter):
Expand Down
5 changes: 5 additions & 0 deletions test_elasticsearch_dsl/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def test_repr():

assert "Terms(some__path='value')" == repr(f)

def test_and_can_be_created_from_list():
f = filter.F({'and': [{'term': {'f': 'v'}}, {'term': {'f2': 42}}]})

assert f == filter.And([filter.F('term', f='v'), filter.F('term', f2=42)])

def test_empty_F_is_match_all():
f = filter.F()

Expand Down

0 comments on commit d677bd7

Please sign in to comment.