From 6ce152ff6c5c3080af22c5dd68b1b02caaa1cbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20W=C3=B3jcicki?= Date: Wed, 11 Sep 2024 17:11:00 +0200 Subject: [PATCH] Removed unnecessary `filter` argument in `AggBase.__getitem__` (#1903) * Remove excessive filter kwarg appearing in AggBase direct aggregation access (#1902) * Typo (#1902) --- elasticsearch_dsl/aggs.py | 2 +- tests/test_aggs.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/elasticsearch_dsl/aggs.py b/elasticsearch_dsl/aggs.py index ef032f7a..df677ba2 100644 --- a/elasticsearch_dsl/aggs.py +++ b/elasticsearch_dsl/aggs.py @@ -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 diff --git a/tests/test_aggs.py b/tests/test_aggs.py index 0fdf3306..30b39c3a 100644 --- a/tests/test_aggs.py +++ b/tests/test_aggs.py @@ -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