Skip to content

Remove deprecation warnings when using body parameter #2302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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