Skip to content

Commit

Permalink
Bugfix when building not filter multiple times
Browse files Browse the repository at this point in the history
Make a copy of `filter` otherwise the `field` value (a :class:`Filter`)
of the `not` filter will be replaced with a `dict` and on next
call of `build_filter` with the same filter_obj variable will fail.
  • Loading branch information
dakra committed Oct 17, 2016
1 parent ce09828 commit b09835f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions pydruid/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def build_filter(filter_obj):
filter = filter.copy() # make a copy so we don't overwrite `fields`
filter['fields'] = [Filter.build_filter(f) for f in filter['fields']]
elif filter['type'] in ['not']:
filter = filter.copy()
filter['field'] = Filter.build_filter(filter['field'])

return filter
Expand Down
7 changes: 5 additions & 2 deletions tests/utils/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ def test_or_filter_multiple(self):
assert actual == expected

def test_not_filter(self):
f = filters.Filter(dimension='dim', value='val')
actual = filters.Filter.build_filter(~f)
f = ~filters.Filter(dimension='dim', value='val')
actual = filters.Filter.build_filter(f)
# Call `build_filter` twice to make sure it does not
# change the passed filter object argument `f`.
actual = filters.Filter.build_filter(f)
expected = {
'type': 'not',
'field': {'type': 'selector', 'dimension': 'dim', 'value': 'val'}
Expand Down

0 comments on commit b09835f

Please sign in to comment.