Skip to content

Commit 7e73534

Browse files
[8.4] Fix timeout related parameters in the options() method
Co-authored-by: Miriam Eid <93708060+miriam-eid@users.noreply.github.com>
1 parent 2f64b0c commit 7e73534

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,26 +519,36 @@ def options(
519519

520520
if request_timeout is not DEFAULT:
521521
client._request_timeout = request_timeout
522+
else:
523+
client._request_timeout = self._request_timeout
522524

523525
if ignore_status is not DEFAULT:
524526
if isinstance(ignore_status, int):
525527
ignore_status = (ignore_status,)
526528
client._ignore_status = ignore_status
529+
else:
530+
client._ignore_status = self._ignore_status
527531

528532
if max_retries is not DEFAULT:
529533
if not isinstance(max_retries, int):
530534
raise TypeError("'max_retries' must be of type 'int'")
531535
client._max_retries = max_retries
536+
else:
537+
client._max_retries = self._max_retries
532538

533539
if retry_on_status is not DEFAULT:
534540
if isinstance(retry_on_status, int):
535541
retry_on_status = (retry_on_status,)
536542
client._retry_on_status = retry_on_status
543+
else:
544+
client._retry_on_status = self._retry_on_status
537545

538546
if retry_on_timeout is not DEFAULT:
539547
if not isinstance(retry_on_timeout, bool):
540548
raise TypeError("'retry_on_timeout' must be of type 'bool'")
541549
client._retry_on_timeout = retry_on_timeout
550+
else:
551+
client._retry_on_timeout = self._retry_on_timeout
542552

543553
return client
544554

elasticsearch/_sync/client/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,26 +519,36 @@ def options(
519519

520520
if request_timeout is not DEFAULT:
521521
client._request_timeout = request_timeout
522+
else:
523+
client._request_timeout = self._request_timeout
522524

523525
if ignore_status is not DEFAULT:
524526
if isinstance(ignore_status, int):
525527
ignore_status = (ignore_status,)
526528
client._ignore_status = ignore_status
529+
else:
530+
client._ignore_status = self._ignore_status
527531

528532
if max_retries is not DEFAULT:
529533
if not isinstance(max_retries, int):
530534
raise TypeError("'max_retries' must be of type 'int'")
531535
client._max_retries = max_retries
536+
else:
537+
client._max_retries = self._max_retries
532538

533539
if retry_on_status is not DEFAULT:
534540
if isinstance(retry_on_status, int):
535541
retry_on_status = (retry_on_status,)
536542
client._retry_on_status = retry_on_status
543+
else:
544+
client._retry_on_status = self._retry_on_status
537545

538546
if retry_on_timeout is not DEFAULT:
539547
if not isinstance(retry_on_timeout, bool):
540548
raise TypeError("'retry_on_timeout' must be of type 'bool'")
541549
client._retry_on_timeout = retry_on_timeout
550+
else:
551+
client._retry_on_timeout = self._retry_on_timeout
542552

543553
return client
544554

test_elasticsearch/test_client/test_options.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,104 @@ def test_user_agent_override(self):
368368
"user-agent": "custom4",
369369
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
370370
}
371+
372+
def test_options_timeout_parameters(self):
373+
client = Elasticsearch(
374+
"http://localhost:9200",
375+
transport_class=DummyTransport,
376+
request_timeout=1,
377+
max_retries=2,
378+
retry_on_status=(404,),
379+
retry_on_timeout=True,
380+
)
381+
382+
# timeout parameters are preserved with .options()
383+
client.options().indices.get(index="test")
384+
385+
calls = client.transport.calls
386+
call = calls[("GET", "/test")][0]
387+
assert call.pop("client_meta") is DEFAULT
388+
assert call == {
389+
"headers": {
390+
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
391+
},
392+
"body": None,
393+
"request_timeout": 1,
394+
"max_retries": 2,
395+
"retry_on_status": (404,),
396+
"retry_on_timeout": True,
397+
}
398+
399+
client = Elasticsearch(
400+
"http://localhost:9200",
401+
transport_class=DummyTransport,
402+
request_timeout=1,
403+
max_retries=2,
404+
retry_on_status=(404,),
405+
retry_on_timeout=True,
406+
)
407+
client.options(
408+
request_timeout=2,
409+
max_retries=3,
410+
retry_on_status=(400,),
411+
retry_on_timeout=False,
412+
).indices.get(index="test")
413+
414+
calls = client.transport.calls
415+
call = calls[("GET", "/test")][0]
416+
assert call.pop("client_meta") is DEFAULT
417+
assert call == {
418+
"headers": {
419+
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
420+
},
421+
"body": None,
422+
"request_timeout": 2,
423+
"max_retries": 3,
424+
"retry_on_status": (400,),
425+
"retry_on_timeout": False,
426+
}
427+
428+
client = Elasticsearch(
429+
"http://localhost:9200",
430+
transport_class=DummyTransport,
431+
)
432+
client.options().indices.get(index="test")
433+
434+
calls = client.transport.calls
435+
call = calls[("GET", "/test")][0]
436+
assert call.pop("request_timeout") is DEFAULT
437+
assert call.pop("max_retries") is DEFAULT
438+
assert call.pop("retry_on_timeout") is DEFAULT
439+
assert call.pop("retry_on_status") is DEFAULT
440+
assert call.pop("client_meta") is DEFAULT
441+
assert call == {
442+
"headers": {
443+
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
444+
},
445+
"body": None,
446+
}
447+
448+
client = Elasticsearch(
449+
"http://localhost:9200",
450+
transport_class=DummyTransport,
451+
)
452+
client.options(
453+
request_timeout=1,
454+
max_retries=2,
455+
retry_on_status=(404,),
456+
retry_on_timeout=True,
457+
).indices.get(index="test")
458+
459+
calls = client.transport.calls
460+
call = calls[("GET", "/test")][0]
461+
assert call.pop("client_meta") is DEFAULT
462+
assert call == {
463+
"headers": {
464+
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
465+
},
466+
"body": None,
467+
"request_timeout": 1,
468+
"max_retries": 2,
469+
"retry_on_status": (404,),
470+
"retry_on_timeout": True,
471+
}

0 commit comments

Comments
 (0)