Skip to content

Commit 5ff3169

Browse files
committed
Accept endpoint_id/path_parts in base clients
1 parent 27c0d70 commit 5ff3169

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

dev-requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
elastic-transport>=8.0.0b1, <9
1+
# TODO switch back to elastic-transport>=8,<9 between elastic-transport release and elasticsearch-py release
2+
elastic-transport @ git+https://github.com/elastic/elastic-transport-python
23
requests>=2, <3
34
aiohttp
45
pytest
@@ -28,4 +29,4 @@ protobuf<4; python_version<="3.7"
2829
# Override Read the Docs default (sphinx<2 and sphinx-rtd-theme<0.5)
2930
sphinx>2
3031
sphinx-rtd-theme>0.5
31-
sphinx-autodoc-typehints
32+
sphinx-autodoc-typehints

elasticsearch/_async/client/_base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ async def perform_request(
257257
params: Optional[Mapping[str, Any]] = None,
258258
headers: Optional[Mapping[str, str]] = None,
259259
body: Optional[Any] = None,
260+
endpoint_id: Union[DefaultType, str] = DEFAULT,
261+
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
260262
) -> ApiResponse[Any]:
261263
if headers:
262264
request_headers = self._headers.copy()
@@ -292,6 +294,8 @@ def mimetype_header_to_compat(header: str) -> None:
292294
retry_on_status=self._retry_on_status,
293295
retry_on_timeout=self._retry_on_timeout,
294296
client_meta=self._client_meta,
297+
endpoint_id=endpoint_id,
298+
path_parts=path_parts,
295299
)
296300

297301
# HEAD with a 404 is returned as a normal response
@@ -383,9 +387,17 @@ async def perform_request(
383387
params: Optional[Mapping[str, Any]] = None,
384388
headers: Optional[Mapping[str, str]] = None,
385389
body: Optional[Any] = None,
390+
endpoint_id: Union[DefaultType, str] = DEFAULT,
391+
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
386392
) -> ApiResponse[Any]:
387393
# Use the internal clients .perform_request() implementation
388394
# so we take advantage of their transport options.
389395
return await self._client.perform_request(
390-
method, path, params=params, headers=headers, body=body
396+
method,
397+
path,
398+
params=params,
399+
headers=headers,
400+
body=body,
401+
endpoint_id=endpoint_id,
402+
path_parts=path_parts,
391403
)

elasticsearch/_sync/client/_base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def perform_request(
257257
params: Optional[Mapping[str, Any]] = None,
258258
headers: Optional[Mapping[str, str]] = None,
259259
body: Optional[Any] = None,
260+
endpoint_id: Union[DefaultType, str] = DEFAULT,
261+
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
260262
) -> ApiResponse[Any]:
261263
if headers:
262264
request_headers = self._headers.copy()
@@ -292,6 +294,8 @@ def mimetype_header_to_compat(header: str) -> None:
292294
retry_on_status=self._retry_on_status,
293295
retry_on_timeout=self._retry_on_timeout,
294296
client_meta=self._client_meta,
297+
endpoint_id=endpoint_id,
298+
path_parts=path_parts,
295299
)
296300

297301
# HEAD with a 404 is returned as a normal response
@@ -383,9 +387,17 @@ def perform_request(
383387
params: Optional[Mapping[str, Any]] = None,
384388
headers: Optional[Mapping[str, str]] = None,
385389
body: Optional[Any] = None,
390+
endpoint_id: Union[DefaultType, str] = DEFAULT,
391+
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
386392
) -> ApiResponse[Any]:
387393
# Use the internal clients .perform_request() implementation
388394
# so we take advantage of their transport options.
389395
return self._client.perform_request(
390-
method, path, params=params, headers=headers, body=body
396+
method,
397+
path,
398+
params=params,
399+
headers=headers,
400+
body=body,
401+
endpoint_id=endpoint_id,
402+
path_parts=path_parts,
391403
)

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151
if package == package_name or package.startswith(package_name + ".")
5252
]
5353

54-
install_requires = ["elastic-transport>=8,<9"]
54+
# TODO switch back to elastic-transport>=8,<9 between elastic-transport release and elasticsearch-py release
55+
install_requires = [
56+
"elastic-transport @ git+https://github.com/elastic/elastic-transport-python"
57+
]
5558
async_requires = ["aiohttp>=3,<4"]
5659

5760
setup(

test_elasticsearch/test_client/test_options.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def test_options_passed_to_perform_request(self):
142142
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
143143
},
144144
"body": None,
145+
"endpoint_id": "indices.get",
146+
"path_parts": {"index": "test"},
145147
}
146148

147149
# Can be overwritten with .options()
@@ -160,6 +162,8 @@ def test_options_passed_to_perform_request(self):
160162
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
161163
},
162164
"body": None,
165+
"endpoint_id": "indices.get",
166+
"path_parts": {"index": "test"},
163167
"request_timeout": 1,
164168
"max_retries": 2,
165169
"retry_on_status": (404,),
@@ -185,6 +189,8 @@ def test_options_passed_to_perform_request(self):
185189
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
186190
},
187191
"body": None,
192+
"endpoint_id": "indices.get",
193+
"path_parts": {"index": "test"},
188194
"request_timeout": 1,
189195
"max_retries": 2,
190196
"retry_on_status": (404,),
@@ -212,6 +218,8 @@ async def test_options_passed_to_async_perform_request(self):
212218
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
213219
},
214220
"body": None,
221+
"endpoint_id": "indices.get",
222+
"path_parts": {"index": "test"},
215223
}
216224

217225
# Can be overwritten with .options()
@@ -230,6 +238,8 @@ async def test_options_passed_to_async_perform_request(self):
230238
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
231239
},
232240
"body": None,
241+
"endpoint_id": "indices.get",
242+
"path_parts": {"index": "test"},
233243
"request_timeout": 1,
234244
"max_retries": 2,
235245
"retry_on_status": (404,),
@@ -255,6 +265,8 @@ async def test_options_passed_to_async_perform_request(self):
255265
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
256266
},
257267
"body": None,
268+
"endpoint_id": "indices.get",
269+
"path_parts": {"index": "test"},
258270
"request_timeout": 1,
259271
"max_retries": 2,
260272
"retry_on_status": (404,),
@@ -390,6 +402,8 @@ def test_options_timeout_parameters(self):
390402
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
391403
},
392404
"body": None,
405+
"endpoint_id": "indices.get",
406+
"path_parts": {"index": "test"},
393407
"request_timeout": 1,
394408
"max_retries": 2,
395409
"retry_on_status": (404,),
@@ -419,6 +433,8 @@ def test_options_timeout_parameters(self):
419433
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
420434
},
421435
"body": None,
436+
"endpoint_id": "indices.get",
437+
"path_parts": {"index": "test"},
422438
"request_timeout": 2,
423439
"max_retries": 3,
424440
"retry_on_status": (400,),
@@ -443,6 +459,8 @@ def test_options_timeout_parameters(self):
443459
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
444460
},
445461
"body": None,
462+
"endpoint_id": "indices.get",
463+
"path_parts": {"index": "test"},
446464
}
447465

448466
client = Elasticsearch(
@@ -464,6 +482,8 @@ def test_options_timeout_parameters(self):
464482
"accept": "application/vnd.elasticsearch+json; compatible-with=8",
465483
},
466484
"body": None,
485+
"endpoint_id": "indices.get",
486+
"path_parts": {"index": "test"},
467487
"request_timeout": 1,
468488
"max_retries": 2,
469489
"retry_on_status": (404,),

0 commit comments

Comments
 (0)