Skip to content

Commit

Permalink
Removed unnecessary filter argument in AggBase.__getitem__ (elast…
Browse files Browse the repository at this point in the history
…ic#1903)

* Remove excessive filter kwarg appearing in AggBase direct aggregation access (elastic#1902)

* Typo (elastic#1902)
  • Loading branch information
rikkt0r authored and miguelgrinberg committed Dec 9, 2024
1 parent c09a259 commit 6ce152f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion elasticsearch_dsl/aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __getitem__(self, agg_name: str) -> Agg[_R]:
# make sure we're not mutating a shared state - whenever accessing a
# bucket, return a shallow copy of it to be safe
if isinstance(agg, Bucket):
agg = A(agg.name, filter=None, **agg._params)
agg = A(agg.name, **agg._params)
# be sure to store the copy so any modifications to it will affect us
self._params["aggs"][agg_name] = agg

Expand Down
9 changes: 9 additions & 0 deletions tests/test_aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,12 @@ def test_top_metrics_aggregation() -> None:
assert {
"top_metrics": {"metrics": {"field": "m"}, "sort": {"s": "desc"}}
} == a.to_dict()


def test_bucket_agg_with_filter() -> None:
b = aggs.Filter(query.Terms(something=[1, 2, 3]))

a = aggs.Terms(field="some_field", size=100)
a.bucket("b", b)

assert a.aggs["b"] == a["b"] # a['b'] threw exception before patch #1902

0 comments on commit 6ce152f

Please sign in to comment.