Skip to content

Commit 387653f

Browse files
pquentinmiguelgrinberg
authored andcommitted
Remove deprecated Elasticsearch() options (elastic#2840)
(cherry picked from commit 20e09c3)
1 parent a35da3c commit 387653f

File tree

9 files changed

+59
-437
lines changed

9 files changed

+59
-437
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 1 addition & 94 deletions
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,
@@ -181,37 +180,12 @@ def __init__(
181180
t.Callable[[t.Dict[str, t.Any], NodeConfig], t.Optional[NodeConfig]]
182181
] = None,
183182
meta_header: t.Union[DefaultType, bool] = DEFAULT,
184-
timeout: t.Union[DefaultType, None, float] = DEFAULT,
185-
randomize_hosts: t.Union[DefaultType, bool] = DEFAULT,
186-
host_info_callback: t.Optional[
187-
t.Callable[
188-
[t.Dict[str, t.Any], t.Dict[str, t.Union[str, int]]],
189-
t.Optional[t.Dict[str, t.Union[str, int]]],
190-
]
191-
] = None,
192-
sniffer_timeout: t.Union[DefaultType, None, float] = DEFAULT,
193-
sniff_on_connection_fail: t.Union[DefaultType, bool] = DEFAULT,
194-
http_auth: t.Union[DefaultType, t.Any] = DEFAULT,
195-
maxsize: t.Union[DefaultType, int] = DEFAULT,
196183
# Internal use only
197184
_transport: t.Optional[AsyncTransport] = None,
198185
) -> None:
199186
if hosts is None and cloud_id is None and _transport is None:
200187
raise ValueError("Either 'hosts' or 'cloud_id' must be specified")
201188

202-
if timeout is not DEFAULT:
203-
if request_timeout is not DEFAULT:
204-
raise ValueError(
205-
"Can't specify both 'timeout' and 'request_timeout', "
206-
"instead only specify 'request_timeout'"
207-
)
208-
warnings.warn(
209-
"The 'timeout' parameter is deprecated in favor of 'request_timeout'",
210-
category=DeprecationWarning,
211-
stacklevel=2,
212-
)
213-
request_timeout = timeout
214-
215189
if serializer is not None:
216190
if serializers is not DEFAULT:
217191
raise ValueError(
@@ -220,58 +194,6 @@ def __init__(
220194
)
221195
serializers = {default_mimetype: serializer}
222196

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

295217
sniff_callback = None
296-
if host_info_callback is not None:
297-
if sniffed_node_callback is not None:
298-
raise ValueError(
299-
"Can't specify both 'host_info_callback' and 'sniffed_node_callback', "
300-
"instead only specify 'sniffed_node_callback'"
301-
)
302-
warnings.warn(
303-
"The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'",
304-
category=DeprecationWarning,
305-
stacklevel=2,
306-
)
307-
308-
sniff_callback = create_sniff_callback(
309-
host_info_callback=host_info_callback
310-
)
311-
elif sniffed_node_callback is not None:
218+
if sniffed_node_callback is not None:
312219
sniff_callback = create_sniff_callback(
313220
sniffed_node_callback=sniffed_node_callback
314221
)

elasticsearch/_sync/client/__init__.py

Lines changed: 1 addition & 94 deletions
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,
@@ -181,37 +180,12 @@ def __init__(
181180
t.Callable[[t.Dict[str, t.Any], NodeConfig], t.Optional[NodeConfig]]
182181
] = None,
183182
meta_header: t.Union[DefaultType, bool] = DEFAULT,
184-
timeout: t.Union[DefaultType, None, float] = DEFAULT,
185-
randomize_hosts: t.Union[DefaultType, bool] = DEFAULT,
186-
host_info_callback: t.Optional[
187-
t.Callable[
188-
[t.Dict[str, t.Any], t.Dict[str, t.Union[str, int]]],
189-
t.Optional[t.Dict[str, t.Union[str, int]]],
190-
]
191-
] = None,
192-
sniffer_timeout: t.Union[DefaultType, None, float] = DEFAULT,
193-
sniff_on_connection_fail: t.Union[DefaultType, bool] = DEFAULT,
194-
http_auth: t.Union[DefaultType, t.Any] = DEFAULT,
195-
maxsize: t.Union[DefaultType, int] = DEFAULT,
196183
# Internal use only
197184
_transport: t.Optional[Transport] = None,
198185
) -> None:
199186
if hosts is None and cloud_id is None and _transport is None:
200187
raise ValueError("Either 'hosts' or 'cloud_id' must be specified")
201188

202-
if timeout is not DEFAULT:
203-
if request_timeout is not DEFAULT:
204-
raise ValueError(
205-
"Can't specify both 'timeout' and 'request_timeout', "
206-
"instead only specify 'request_timeout'"
207-
)
208-
warnings.warn(
209-
"The 'timeout' parameter is deprecated in favor of 'request_timeout'",
210-
category=DeprecationWarning,
211-
stacklevel=2,
212-
)
213-
request_timeout = timeout
214-
215189
if serializer is not None:
216190
if serializers is not DEFAULT:
217191
raise ValueError(
@@ -220,58 +194,6 @@ def __init__(
220194
)
221195
serializers = {default_mimetype: serializer}
222196

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

295217
sniff_callback = None
296-
if host_info_callback is not None:
297-
if sniffed_node_callback is not None:
298-
raise ValueError(
299-
"Can't specify both 'host_info_callback' and 'sniffed_node_callback', "
300-
"instead only specify 'sniffed_node_callback'"
301-
)
302-
warnings.warn(
303-
"The 'host_info_callback' parameter is deprecated in favor of 'sniffed_node_callback'",
304-
category=DeprecationWarning,
305-
stacklevel=2,
306-
)
307-
308-
sniff_callback = create_sniff_callback(
309-
host_info_callback=host_info_callback
310-
)
311-
elif sniffed_node_callback is not None:
218+
if sniffed_node_callback is not None:
312219
sniff_callback = create_sniff_callback(
313220
sniffed_node_callback=sniffed_node_callback
314221
)

test_elasticsearch/test_async/test_transport.py

Lines changed: 1 addition & 39 deletions
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)