Skip to content

Commit

Permalink
[Backport 8.10] Remove deprecation warnings when using body parameter (
Browse files Browse the repository at this point in the history
…#2308)

* Remove deprecation warnings when using body parameter (#2302)

(cherry picked from commit 6ec5c9e)

Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
  • Loading branch information
github-actions[bot] and pquentin authored Sep 25, 2023
1 parent ca45614 commit 9025479
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
15 changes: 0 additions & 15 deletions elasticsearch/_sync/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,6 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
f"'{body_name}' parameter. See https://github.com/elastic/elasticsearch-py/"
"issues/1698 for more information"
)

warnings.warn(
"The 'body' parameter is deprecated and will be removed "
f"in a future version. Instead use the '{body_name}' parameter. "
"See https://github.com/elastic/elasticsearch-py/issues/1698 "
"for more information",
category=DeprecationWarning,
stacklevel=warn_stacklevel(),
)
kwargs[body_name] = body

elif body_fields:
Expand All @@ -396,12 +387,6 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
"Couldn't merge 'body' with other parameters as it wasn't a mapping. "
"Instead of using 'body' use individual API parameters"
)
warnings.warn(
"The 'body' parameter is deprecated and will be removed "
"in a future version. Instead use individual parameters.",
category=DeprecationWarning,
stacklevel=warn_stacklevel(),
)
_merge_kwargs_no_duplicates(kwargs, body)

if parameter_aliases:
Expand Down
14 changes: 2 additions & 12 deletions test_elasticsearch/test_client/test_rewrite_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,12 @@ def test_body_name_using_body(self):
api_key=("id", "api_key"), body={"query": {"match_all": {}}}
)

assert len(w) == 2
assert len(w) == 1
assert w[0].category == DeprecationWarning
assert (
str(w[0].message)
== "Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead."
)
assert w[1].category == DeprecationWarning
assert str(w[1].message) == (
"The 'body' parameter is deprecated and will be removed in a "
"future version. Instead use the 'document' parameter. See https://github.com/elastic/elasticsearch-py/issues/1698 "
"for more information"
)

assert self.calls == [
((), {"api_key": ("id", "api_key")}),
Expand Down Expand Up @@ -139,16 +133,12 @@ def test_body_fields(self):
api_key=("id", "api_key"), body={"query": {"match_all": {}}}
)

assert len(w) == 2
assert len(w) == 1
assert w[0].category == DeprecationWarning
assert (
str(w[0].message)
== "Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead."
)
assert w[1].category == DeprecationWarning
assert str(w[1].message) == (
"The 'body' parameter is deprecated and will be removed in a future version. Instead use individual parameters."
)

assert self.calls == [
((), {"api_key": ("id", "api_key")}),
Expand Down

0 comments on commit 9025479

Please sign in to comment.