From 8e79b8b1150a0885471ce19a17f026f625aa1f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20W=C3=B3jcicki?= Date: Fri, 6 Sep 2024 17:50:05 +0200 Subject: [PATCH 1/2] Remove excessive filter kwarg appearing in AggBase direct aggregation access (#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..ca6d1157 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.aggs['b'] threw exception before patch #1902 From fda47ad310c82ff02dc06d6d2b1c924067f26915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20W=C3=B3jcicki?= Date: Fri, 6 Sep 2024 17:56:17 +0200 Subject: [PATCH 2/2] Typo (#1902) --- tests/test_aggs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_aggs.py b/tests/test_aggs.py index ca6d1157..30b39c3a 100644 --- a/tests/test_aggs.py +++ b/tests/test_aggs.py @@ -484,4 +484,4 @@ def test_bucket_agg_with_filter() -> None: a = aggs.Terms(field="some_field", size=100) a.bucket("b", b) - assert a.aggs["b"] == a["b"] # a.aggs['b'] threw exception before patch #1902 + assert a.aggs["b"] == a["b"] # a['b'] threw exception before patch #1902