From 5f75ff98b73b8913bc7b158c9caeaa59e04cf953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Godefroy=20Amaury=20de=20Malef=C3=A8te?= Date: Thu, 25 Jul 2024 18:16:42 +0200 Subject: [PATCH] fixup! Allow the use of percent string in Bool.__and__ method --- opensearchpy/helpers/query.py | 5 --- test_opensearchpy/test_helpers/test_query.py | 36 ++++---------------- 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/opensearchpy/helpers/query.py b/opensearchpy/helpers/query.py index 11980d14..fa12e6d7 100644 --- a/opensearchpy/helpers/query.py +++ b/opensearchpy/helpers/query.py @@ -221,11 +221,6 @@ def __and__(self, other: "Bool") -> Any: for qx in (self, other): min_should_match = qx._min_should_match - - # attempt to convert a string integer representation to int - with contextlib.suppress(ValueError): - min_should_match = int(min_should_match) - # all subqueries are required if ( isinstance(min_should_match, int) diff --git a/test_opensearchpy/test_helpers/test_query.py b/test_opensearchpy/test_helpers/test_query.py index 67b370e0..e6d6dddc 100644 --- a/test_opensearchpy/test_helpers/test_query.py +++ b/test_opensearchpy/test_helpers/test_query.py @@ -567,18 +567,11 @@ def test_script_score() -> None: @pytest.mark.parametrize( # type: ignore[misc] - "minimum_should_match, expected_type", - [ - ("1", int), - ("-1", int), - ("50%", str), - ("-50%", str), - ("1<50%", str), - ], + "minimum_should_match", + [1, -1, "1", "-1", "50%", "-50%", "1<50%"], ) -def test_bool_with_minimum_should_match_as_string( +def test_bool_with_minimum_should_match_as_int_or_string( minimum_should_match: str, - expected_type: Type[Union[str, int]], ) -> None: q1 = query.Bool( @@ -601,7 +594,7 @@ def test_bool_with_minimum_should_match_as_string( d1 = { "bool": { - "minimum_should_match": minimum_should_match, + "minimum_should_match": minimum_should_match, # input type is preserved "should": [ {"term": {"field": "aa1"}}, {"term": {"field": "aa2"}}, @@ -611,7 +604,7 @@ def test_bool_with_minimum_should_match_as_string( d2 = { "bool": { - "minimum_should_match": minimum_should_match, + "minimum_should_match": minimum_should_match, # input type is preserved "should": [ {"term": {"field": "bb1"}}, {"term": {"field": "bb2"}}, @@ -620,24 +613,7 @@ def test_bool_with_minimum_should_match_as_string( } d3 = { - "bool": { - "should": [ - {"term": {"field": "aa1"}}, - {"term": {"field": "aa2"}}, - ], - "must": [ - { - "bool": { - "should": [ - {"term": {"field": "bb1"}}, - {"term": {"field": "bb2"}}, - ], - "minimum_should_match": expected_type(minimum_should_match), - } - } - ], - "minimum_should_match": expected_type(minimum_should_match), - } + "bool": {**d1["bool"], "must": [d2]}, } assert q1.to_dict() == d1