Skip to content

Commit 961dd2b

Browse files
Remove deprecated Elasticsearch() options (#2840) (#2876)
(cherry picked from commit 20e09c3) Co-authored-by: Quentin Pradet <[email protected]>
1 parent 59deef2 commit 961dd2b

File tree

9 files changed

+59
-409
lines changed

9 files changed

+59
-409
lines changed

Diff for: elasticsearch/_async/client/__init__.py

+1-93
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import logging
2020
import typing as t
21-
import warnings
2221

2322
from elastic_transport import (
2423
AsyncTransport,
@@ -179,36 +178,12 @@ def __init__(
179178
t.Callable[[t.Dict[str, t.Any], NodeConfig], t.Optional[NodeConfig]]
180179
] = None,
181180
meta_header: t.Union[DefaultType, bool] = DEFAULT,
182-
timeout: t.Union[DefaultType, None, float] = DEFAULT,
183-
randomize_hosts: t.Union[DefaultType, bool] = DEFAULT,
184-
host_info_callback: t.Optional[
185-
t.Callable[
186-
[t.Dict[str, t.Any], t.Dict[str, t.Union[str, int]]],
187-
t.Optional[t.Dict[str, t.Union[str, int]]],
188-
]
189-
] = None,
190-
sniffer_timeout: t.Union[DefaultType, None, float] = DEFAULT,
191-
sniff_on_connection_fail: t.Union[DefaultType, bool] = DEFAULT,
192-
maxsize: t.Union[DefaultType, int] = DEFAULT,
193181
# Internal use only
194182
_transport: t.Optional[AsyncTransport] = None,
195183
) -> None:
196184
if hosts is None and cloud_id is None and _transport is None:
197185
raise ValueError("Either 'hosts' or 'cloud_id' must be specified")
198186

199-
if timeout is not DEFAULT:
200-
if request_timeout is not DEFAULT:
201-
raise ValueError(
202-
"Can't specify both 'timeout' and 'request_timeout', "
203-
"instead only specify 'request_timeout'"
204-
)
205-
warnings.warn(
206-
"The 'timeout' parameter is deprecated in favor of 'request_timeout'",
207-
category=DeprecationWarning,
208-
stacklevel=2,
209-
)
210-
request_timeout = timeout
211-
212187
if serializer is not None:
213188
if serializers is not DEFAULT:
214189
raise ValueError(
@@ -217,58 +192,6 @@ def __init__(
217192
)
218193
serializers = {default_mimetype: serializer}
219194

220-
if randomize_hosts is not DEFAULT:
221-
if randomize_nodes_in_pool is not DEFAULT:
222-
raise ValueError(
223-
"Can't specify both 'randomize_hosts' and 'randomize_nodes_in_pool', "
224-
"instead only specify 'randomize_nodes_in_pool'"
225-
)
226-
warnings.warn(
227-
"The 'randomize_hosts' parameter is deprecated in favor of 'randomize_nodes_in_pool'",
228-
category=DeprecationWarning,
229-
stacklevel=2,
230-
)
231-
randomize_nodes_in_pool = randomize_hosts
232-
233-
if sniffer_timeout is not DEFAULT:
234-
if min_delay_between_sniffing is not DEFAULT:
235-
raise ValueError(
236-
"Can't specify both 'sniffer_timeout' and 'min_delay_between_sniffing', "
237-
"instead only specify 'min_delay_between_sniffing'"
238-
)
239-
warnings.warn(
240-
"The 'sniffer_timeout' parameter is deprecated in favor of 'min_delay_between_sniffing'",
241-
category=DeprecationWarning,
242-
stacklevel=2,
243-
)
244-
min_delay_between_sniffing = sniffer_timeout
245-
246-
if sniff_on_connection_fail is not DEFAULT:
247-
if sniff_on_node_failure is not DEFAULT:
248-
raise ValueError(
249-
"Can't specify both 'sniff_on_connection_fail' and 'sniff_on_node_failure', "
250-
"instead only specify 'sniff_on_node_failure'"
251-
)
252-
warnings.warn(
253-
"The 'sniff_on_connection_fail' parameter is deprecated in favor of 'sniff_on_node_failure'",
254-
category=DeprecationWarning,
255-
stacklevel=2,
256-
)
257-
sniff_on_node_failure = sniff_on_connection_fail
258-
259-
if maxsize is not DEFAULT:
260-
if connections_per_node is not DEFAULT:
261-
raise ValueError(
262-
"Can't specify both 'maxsize' and 'connections_per_node', "
263-
"instead only specify 'connections_per_node'"
264-
)
265-
warnings.warn(
266-
"The 'maxsize' parameter is deprecated in favor of 'connections_per_node'",
267-
category=DeprecationWarning,
268-
stacklevel=2,
269-
)
270-
connections_per_node = maxsize
271-
272195
# Setting min_delay_between_sniffing=True implies sniff_before_requests=True
273196
if min_delay_between_sniffing is not DEFAULT:
274197
sniff_before_requests = True
@@ -290,22 +213,7 @@ def __init__(
290213
)
291214

292215
sniff_callback = None
293-
if host_info_callback is not None:
294-
if sniffed_node_callback is not None:
295-
raise ValueError(
296-
"Can't specify both 'host_info_callback' and 'sniffed_node_callback', "
297-
"instead only specify 'sniffed_node_callback'"
298-
)
299-
warnings.warn(
300-
"The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'",
301-
category=DeprecationWarning,
302-
stacklevel=2,
303-
)
304-
305-
sniff_callback = create_sniff_callback(
306-
host_info_callback=host_info_callback
307-
)
308-
elif sniffed_node_callback is not None:
216+
if sniffed_node_callback is not None:
309217
sniff_callback = create_sniff_callback(
310218
sniffed_node_callback=sniffed_node_callback
311219
)

Diff for: elasticsearch/_sync/client/__init__.py

+1-93
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import logging
2020
import typing as t
21-
import warnings
2221

2322
from elastic_transport import (
2423
BaseNode,
@@ -179,36 +178,12 @@ def __init__(
179178
t.Callable[[t.Dict[str, t.Any], NodeConfig], t.Optional[NodeConfig]]
180179
] = None,
181180
meta_header: t.Union[DefaultType, bool] = DEFAULT,
182-
timeout: t.Union[DefaultType, None, float] = DEFAULT,
183-
randomize_hosts: t.Union[DefaultType, bool] = DEFAULT,
184-
host_info_callback: t.Optional[
185-
t.Callable[
186-
[t.Dict[str, t.Any], t.Dict[str, t.Union[str, int]]],
187-
t.Optional[t.Dict[str, t.Union[str, int]]],
188-
]
189-
] = None,
190-
sniffer_timeout: t.Union[DefaultType, None, float] = DEFAULT,
191-
sniff_on_connection_fail: t.Union[DefaultType, bool] = DEFAULT,
192-
maxsize: t.Union[DefaultType, int] = DEFAULT,
193181
# Internal use only
194182
_transport: t.Optional[Transport] = None,
195183
) -> None:
196184
if hosts is None and cloud_id is None and _transport is None:
197185
raise ValueError("Either 'hosts' or 'cloud_id' must be specified")
198186

199-
if timeout is not DEFAULT:
200-
if request_timeout is not DEFAULT:
201-
raise ValueError(
202-
"Can't specify both 'timeout' and 'request_timeout', "
203-
"instead only specify 'request_timeout'"
204-
)
205-
warnings.warn(
206-
"The 'timeout' parameter is deprecated in favor of 'request_timeout'",
207-
category=DeprecationWarning,
208-
stacklevel=2,
209-
)
210-
request_timeout = timeout
211-
212187
if serializer is not None:
213188
if serializers is not DEFAULT:
214189
raise ValueError(
@@ -217,58 +192,6 @@ def __init__(
217192
)
218193
serializers = {default_mimetype: serializer}
219194

220-
if randomize_hosts is not DEFAULT:
221-
if randomize_nodes_in_pool is not DEFAULT:
222-
raise ValueError(
223-
"Can't specify both 'randomize_hosts' and 'randomize_nodes_in_pool', "
224-
"instead only specify 'randomize_nodes_in_pool'"
225-
)
226-
warnings.warn(
227-
"The 'randomize_hosts' parameter is deprecated in favor of 'randomize_nodes_in_pool'",
228-
category=DeprecationWarning,
229-
stacklevel=2,
230-
)
231-
randomize_nodes_in_pool = randomize_hosts
232-
233-
if sniffer_timeout is not DEFAULT:
234-
if min_delay_between_sniffing is not DEFAULT:
235-
raise ValueError(
236-
"Can't specify both 'sniffer_timeout' and 'min_delay_between_sniffing', "
237-
"instead only specify 'min_delay_between_sniffing'"
238-
)
239-
warnings.warn(
240-
"The 'sniffer_timeout' parameter is deprecated in favor of 'min_delay_between_sniffing'",
241-
category=DeprecationWarning,
242-
stacklevel=2,
243-
)
244-
min_delay_between_sniffing = sniffer_timeout
245-
246-
if sniff_on_connection_fail is not DEFAULT:
247-
if sniff_on_node_failure is not DEFAULT:
248-
raise ValueError(
249-
"Can't specify both 'sniff_on_connection_fail' and 'sniff_on_node_failure', "
250-
"instead only specify 'sniff_on_node_failure'"
251-
)
252-
warnings.warn(
253-
"The 'sniff_on_connection_fail' parameter is deprecated in favor of 'sniff_on_node_failure'",
254-
category=DeprecationWarning,
255-
stacklevel=2,
256-
)
257-
sniff_on_node_failure = sniff_on_connection_fail
258-
259-
if maxsize is not DEFAULT:
260-
if connections_per_node is not DEFAULT:
261-
raise ValueError(
262-
"Can't specify both 'maxsize' and 'connections_per_node', "
263-
"instead only specify 'connections_per_node'"
264-
)
265-
warnings.warn(
266-
"The 'maxsize' parameter is deprecated in favor of 'connections_per_node'",
267-
category=DeprecationWarning,
268-
stacklevel=2,
269-
)
270-
connections_per_node = maxsize
271-
272195
# Setting min_delay_between_sniffing=True implies sniff_before_requests=True
273196
if min_delay_between_sniffing is not DEFAULT:
274197
sniff_before_requests = True
@@ -290,22 +213,7 @@ def __init__(
290213
)
291214

292215
sniff_callback = None
293-
if host_info_callback is not None:
294-
if sniffed_node_callback is not None:
295-
raise ValueError(
296-
"Can't specify both 'host_info_callback' and 'sniffed_node_callback', "
297-
"instead only specify 'sniffed_node_callback'"
298-
)
299-
warnings.warn(
300-
"The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'",
301-
category=DeprecationWarning,
302-
stacklevel=2,
303-
)
304-
305-
sniff_callback = create_sniff_callback(
306-
host_info_callback=host_info_callback
307-
)
308-
elif sniffed_node_callback is not None:
216+
if sniffed_node_callback is not None:
309217
sniff_callback = create_sniff_callback(
310218
sniffed_node_callback=sniffed_node_callback
311219
)

Diff for: test_elasticsearch/test_async/test_transport.py

+1-39
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import asyncio
2020
import re
2121
import warnings
22-
from typing import Any, Dict, Optional, Union
22+
from typing import Any, Dict, Optional
2323

2424
import pytest
2525
from elastic_transport import (
@@ -562,10 +562,8 @@ async def test_sniff_after_n_seconds(self, event_loop):
562562
"kwargs",
563563
[
564564
{"sniff_on_start": True},
565-
{"sniff_on_connection_fail": True},
566565
{"sniff_on_node_failure": True},
567566
{"sniff_before_requests": True},
568-
{"sniffer_timeout": 1},
569567
{"sniff_timeout": 1},
570568
],
571569
)
@@ -660,42 +658,6 @@ def sniffed_node_callback(
660658
ports = {node.config.port for node in client.transport.node_pool.all()}
661659
assert ports == {9200, 124}
662660

663-
async def test_sniffing_deprecated_host_info_callback(self):
664-
def host_info_callback(
665-
node_info: Dict[str, Any], host: Dict[str, Union[int, str]]
666-
) -> Dict[str, Any]:
667-
return (
668-
host if node_info["http"]["publish_address"].endswith(":124") else None
669-
)
670-
671-
with warnings.catch_warnings(record=True) as w:
672-
client = AsyncElasticsearch( # noqa: F821
673-
[
674-
NodeConfig(
675-
"http",
676-
"localhost",
677-
9200,
678-
_extras={"data": CLUSTER_NODES_MASTER_ONLY},
679-
)
680-
],
681-
node_class=DummyNode,
682-
sniff_on_start=True,
683-
host_info_callback=host_info_callback,
684-
)
685-
await client.transport._async_call()
686-
687-
assert len(w) == 1
688-
assert w[0].category == DeprecationWarning
689-
assert (
690-
str(w[0].message)
691-
== "The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'"
692-
)
693-
694-
assert len(client.transport.node_pool) == 2
695-
696-
ports = {node.config.port for node in client.transport.node_pool.all()}
697-
assert ports == {9200, 124}
698-
699661

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

0 commit comments

Comments
 (0)