diff --git a/pydruid/utils/filters.py b/pydruid/utils/filters.py index a7ae3c22..76254a00 100644 --- a/pydruid/utils/filters.py +++ b/pydruid/utils/filters.py @@ -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 diff --git a/tests/utils/test_filters.py b/tests/utils/test_filters.py index b66142da..21863909 100644 --- a/tests/utils/test_filters.py +++ b/tests/utils/test_filters.py @@ -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'}