Skip to content

Remove deprecated Elasticsearch() options #2840

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
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
94 changes: 1 addition & 93 deletions elasticsearch/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import logging
import typing as t
import warnings

from elastic_transport import (
AsyncTransport,
Expand Down Expand Up @@ -179,36 +178,12 @@ def __init__(
t.Callable[[t.Dict[str, t.Any], NodeConfig], t.Optional[NodeConfig]]
] = None,
meta_header: t.Union[DefaultType, bool] = DEFAULT,
timeout: t.Union[DefaultType, None, float] = DEFAULT,
randomize_hosts: t.Union[DefaultType, bool] = DEFAULT,
host_info_callback: t.Optional[
t.Callable[
[t.Dict[str, t.Any], t.Dict[str, t.Union[str, int]]],
t.Optional[t.Dict[str, t.Union[str, int]]],
]
] = None,
sniffer_timeout: t.Union[DefaultType, None, float] = DEFAULT,
sniff_on_connection_fail: t.Union[DefaultType, bool] = DEFAULT,
maxsize: t.Union[DefaultType, int] = DEFAULT,
# Internal use only
_transport: t.Optional[AsyncTransport] = None,
) -> None:
if hosts is None and cloud_id is None and _transport is None:
raise ValueError("Either 'hosts' or 'cloud_id' must be specified")

if timeout is not DEFAULT:
if request_timeout is not DEFAULT:
raise ValueError(
"Can't specify both 'timeout' and 'request_timeout', "
"instead only specify 'request_timeout'"
)
warnings.warn(
"The 'timeout' parameter is deprecated in favor of 'request_timeout'",
category=DeprecationWarning,
stacklevel=2,
)
request_timeout = timeout

if serializer is not None:
if serializers is not DEFAULT:
raise ValueError(
Expand All @@ -217,58 +192,6 @@ def __init__(
)
serializers = {default_mimetype: serializer}

if randomize_hosts is not DEFAULT:
if randomize_nodes_in_pool is not DEFAULT:
raise ValueError(
"Can't specify both 'randomize_hosts' and 'randomize_nodes_in_pool', "
"instead only specify 'randomize_nodes_in_pool'"
)
warnings.warn(
"The 'randomize_hosts' parameter is deprecated in favor of 'randomize_nodes_in_pool'",
category=DeprecationWarning,
stacklevel=2,
)
randomize_nodes_in_pool = randomize_hosts

if sniffer_timeout is not DEFAULT:
if min_delay_between_sniffing is not DEFAULT:
raise ValueError(
"Can't specify both 'sniffer_timeout' and 'min_delay_between_sniffing', "
"instead only specify 'min_delay_between_sniffing'"
)
warnings.warn(
"The 'sniffer_timeout' parameter is deprecated in favor of 'min_delay_between_sniffing'",
category=DeprecationWarning,
stacklevel=2,
)
min_delay_between_sniffing = sniffer_timeout

if sniff_on_connection_fail is not DEFAULT:
if sniff_on_node_failure is not DEFAULT:
raise ValueError(
"Can't specify both 'sniff_on_connection_fail' and 'sniff_on_node_failure', "
"instead only specify 'sniff_on_node_failure'"
)
warnings.warn(
"The 'sniff_on_connection_fail' parameter is deprecated in favor of 'sniff_on_node_failure'",
category=DeprecationWarning,
stacklevel=2,
)
sniff_on_node_failure = sniff_on_connection_fail

if maxsize is not DEFAULT:
if connections_per_node is not DEFAULT:
raise ValueError(
"Can't specify both 'maxsize' and 'connections_per_node', "
"instead only specify 'connections_per_node'"
)
warnings.warn(
"The 'maxsize' parameter is deprecated in favor of 'connections_per_node'",
category=DeprecationWarning,
stacklevel=2,
)
connections_per_node = maxsize

# Setting min_delay_between_sniffing=True implies sniff_before_requests=True
if min_delay_between_sniffing is not DEFAULT:
sniff_before_requests = True
Expand All @@ -290,22 +213,7 @@ def __init__(
)

sniff_callback = None
if host_info_callback is not None:
if sniffed_node_callback is not None:
raise ValueError(
"Can't specify both 'host_info_callback' and 'sniffed_node_callback', "
"instead only specify 'sniffed_node_callback'"
)
warnings.warn(
"The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'",
category=DeprecationWarning,
stacklevel=2,
)

sniff_callback = create_sniff_callback(
host_info_callback=host_info_callback
)
elif sniffed_node_callback is not None:
if sniffed_node_callback is not None:
sniff_callback = create_sniff_callback(
sniffed_node_callback=sniffed_node_callback
)
Expand Down
94 changes: 1 addition & 93 deletions elasticsearch/_sync/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import logging
import typing as t
import warnings

from elastic_transport import (
BaseNode,
Expand Down Expand Up @@ -179,36 +178,12 @@ def __init__(
t.Callable[[t.Dict[str, t.Any], NodeConfig], t.Optional[NodeConfig]]
] = None,
meta_header: t.Union[DefaultType, bool] = DEFAULT,
timeout: t.Union[DefaultType, None, float] = DEFAULT,
randomize_hosts: t.Union[DefaultType, bool] = DEFAULT,
host_info_callback: t.Optional[
t.Callable[
[t.Dict[str, t.Any], t.Dict[str, t.Union[str, int]]],
t.Optional[t.Dict[str, t.Union[str, int]]],
]
] = None,
sniffer_timeout: t.Union[DefaultType, None, float] = DEFAULT,
sniff_on_connection_fail: t.Union[DefaultType, bool] = DEFAULT,
maxsize: t.Union[DefaultType, int] = DEFAULT,
# Internal use only
_transport: t.Optional[Transport] = None,
) -> None:
if hosts is None and cloud_id is None and _transport is None:
raise ValueError("Either 'hosts' or 'cloud_id' must be specified")

if timeout is not DEFAULT:
if request_timeout is not DEFAULT:
raise ValueError(
"Can't specify both 'timeout' and 'request_timeout', "
"instead only specify 'request_timeout'"
)
warnings.warn(
"The 'timeout' parameter is deprecated in favor of 'request_timeout'",
category=DeprecationWarning,
stacklevel=2,
)
request_timeout = timeout

if serializer is not None:
if serializers is not DEFAULT:
raise ValueError(
Expand All @@ -217,58 +192,6 @@ def __init__(
)
serializers = {default_mimetype: serializer}

if randomize_hosts is not DEFAULT:
if randomize_nodes_in_pool is not DEFAULT:
raise ValueError(
"Can't specify both 'randomize_hosts' and 'randomize_nodes_in_pool', "
"instead only specify 'randomize_nodes_in_pool'"
)
warnings.warn(
"The 'randomize_hosts' parameter is deprecated in favor of 'randomize_nodes_in_pool'",
category=DeprecationWarning,
stacklevel=2,
)
randomize_nodes_in_pool = randomize_hosts

if sniffer_timeout is not DEFAULT:
if min_delay_between_sniffing is not DEFAULT:
raise ValueError(
"Can't specify both 'sniffer_timeout' and 'min_delay_between_sniffing', "
"instead only specify 'min_delay_between_sniffing'"
)
warnings.warn(
"The 'sniffer_timeout' parameter is deprecated in favor of 'min_delay_between_sniffing'",
category=DeprecationWarning,
stacklevel=2,
)
min_delay_between_sniffing = sniffer_timeout

if sniff_on_connection_fail is not DEFAULT:
if sniff_on_node_failure is not DEFAULT:
raise ValueError(
"Can't specify both 'sniff_on_connection_fail' and 'sniff_on_node_failure', "
"instead only specify 'sniff_on_node_failure'"
)
warnings.warn(
"The 'sniff_on_connection_fail' parameter is deprecated in favor of 'sniff_on_node_failure'",
category=DeprecationWarning,
stacklevel=2,
)
sniff_on_node_failure = sniff_on_connection_fail

if maxsize is not DEFAULT:
if connections_per_node is not DEFAULT:
raise ValueError(
"Can't specify both 'maxsize' and 'connections_per_node', "
"instead only specify 'connections_per_node'"
)
warnings.warn(
"The 'maxsize' parameter is deprecated in favor of 'connections_per_node'",
category=DeprecationWarning,
stacklevel=2,
)
connections_per_node = maxsize

# Setting min_delay_between_sniffing=True implies sniff_before_requests=True
if min_delay_between_sniffing is not DEFAULT:
sniff_before_requests = True
Expand All @@ -290,22 +213,7 @@ def __init__(
)

sniff_callback = None
if host_info_callback is not None:
if sniffed_node_callback is not None:
raise ValueError(
"Can't specify both 'host_info_callback' and 'sniffed_node_callback', "
"instead only specify 'sniffed_node_callback'"
)
warnings.warn(
"The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'",
category=DeprecationWarning,
stacklevel=2,
)

sniff_callback = create_sniff_callback(
host_info_callback=host_info_callback
)
elif sniffed_node_callback is not None:
if sniffed_node_callback is not None:
sniff_callback = create_sniff_callback(
sniffed_node_callback=sniffed_node_callback
)
Expand Down
40 changes: 1 addition & 39 deletions test_elasticsearch/test_async/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import asyncio
import re
import warnings
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, Optional

import pytest
from elastic_transport import (
Expand Down Expand Up @@ -562,10 +562,8 @@ async def test_sniff_after_n_seconds(self, event_loop):
"kwargs",
[
{"sniff_on_start": True},
{"sniff_on_connection_fail": True},
{"sniff_on_node_failure": True},
{"sniff_before_requests": True},
{"sniffer_timeout": 1},
{"sniff_timeout": 1},
],
)
Expand Down Expand Up @@ -660,42 +658,6 @@ def sniffed_node_callback(
ports = {node.config.port for node in client.transport.node_pool.all()}
assert ports == {9200, 124}

async def test_sniffing_deprecated_host_info_callback(self):
def host_info_callback(
node_info: Dict[str, Any], host: Dict[str, Union[int, str]]
) -> Dict[str, Any]:
return (
host if node_info["http"]["publish_address"].endswith(":124") else None
)

with warnings.catch_warnings(record=True) as w:
client = AsyncElasticsearch( # noqa: F821
[
NodeConfig(
"http",
"localhost",
9200,
_extras={"data": CLUSTER_NODES_MASTER_ONLY},
)
],
node_class=DummyNode,
sniff_on_start=True,
host_info_callback=host_info_callback,
)
await client.transport._async_call()

assert len(w) == 1
assert w[0].category == DeprecationWarning
assert (
str(w[0].message)
== "The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'"
)

assert len(client.transport.node_pool) == 2

ports = {node.config.port for node in client.transport.node_pool.all()}
assert ports == {9200, 124}


@pytest.mark.parametrize("headers", [{}, {"X-elastic-product": "BAD HEADER"}])
async def test_unsupported_product_error(headers):
Expand Down
Loading
Loading