Skip to content

Commit 04f401a

Browse files
authored
Use 'body' instead of 'raw' for responses
1 parent d622235 commit 04f401a

File tree

12 files changed

+48
-48
lines changed

12 files changed

+48
-48
lines changed

dev-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
elastic-transport>=8.0.0a1, <9
1+
elastic-transport>=8.0.0a7, <9
22
requests>=2, <3
33
aiohttp
44
pytest

elasticsearch/_async/client/_base.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def _perform_request(
248248
target: str,
249249
headers: Optional[Mapping[str, str]] = None,
250250
body: Optional[Any] = None,
251-
) -> ApiResponse[Any, Any]:
251+
) -> ApiResponse[Any]:
252252
if headers:
253253
request_headers = self._headers.copy()
254254
request_headers.update(headers)
@@ -327,18 +327,18 @@ async def _perform_request(
327327
if method == "HEAD":
328328
response = HeadApiResponse(meta=meta)
329329
elif isinstance(resp_body, dict):
330-
response = ObjectApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
330+
response = ObjectApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
331331
elif isinstance(resp_body, list):
332-
response = ListApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
332+
response = ListApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
333333
elif isinstance(resp_body, str):
334334
response = TextApiResponse( # type: ignore[assignment]
335-
raw=resp_body,
335+
body=resp_body,
336336
meta=meta,
337337
)
338338
elif isinstance(resp_body, bytes):
339-
response = BinaryApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
339+
response = BinaryApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
340340
else:
341-
response = ApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
341+
response = ApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
342342

343343
return response
344344

elasticsearch/_async/helpers.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def _process_bulk_chunk(
119119
)
120120
else:
121121
gen = _process_bulk_chunk_success(
122-
resp=resp.raw,
122+
resp=resp.body,
123123
bulk_data=bulk_data,
124124
ignore_status=ignore_status,
125125
raise_on_error=raise_on_error,
@@ -442,20 +442,20 @@ def pop_transport_kwargs(kw: MutableMapping[str, Any]) -> MutableMapping[str, An
442442
search_kwargs["size"] = size
443443
resp = await client.search(body=query, **search_kwargs) # type: ignore[call-arg]
444444

445-
scroll_id: Optional[str] = resp.raw.get("_scroll_id")
445+
scroll_id: Optional[str] = resp.get("_scroll_id")
446446
scroll_transport_kwargs = pop_transport_kwargs(scroll_kwargs)
447447
if scroll_transport_kwargs:
448448
scroll_client = client.options(**scroll_transport_kwargs)
449449
else:
450450
scroll_client = client
451451

452452
try:
453-
while scroll_id and resp.raw["hits"]["hits"]:
454-
for hit in resp.raw["hits"]["hits"]:
453+
while scroll_id and resp["hits"]["hits"]:
454+
for hit in resp["hits"]["hits"]:
455455
yield hit
456456

457457
# Default to 0 if the value isn't included in the response
458-
shards_info: Dict[str, int] = resp.raw["_shards"]
458+
shards_info: Dict[str, int] = resp["_shards"]
459459
shards_successful = shards_info.get("successful", 0)
460460
shards_skipped = shards_info.get("skipped", 0)
461461
shards_total = shards_info.get("total", 0)
@@ -482,7 +482,7 @@ def pop_transport_kwargs(kw: MutableMapping[str, Any]) -> MutableMapping[str, An
482482
resp = await scroll_client.scroll(
483483
scroll_id=scroll_id, scroll=scroll, **scroll_kwargs
484484
)
485-
scroll_id = resp.raw.get("_scroll_id")
485+
scroll_id = resp.get("_scroll_id")
486486

487487
finally:
488488
if scroll_id and clear_scroll:

elasticsearch/_sync/client/_base.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _perform_request(
248248
target: str,
249249
headers: Optional[Mapping[str, str]] = None,
250250
body: Optional[Any] = None,
251-
) -> ApiResponse[Any, Any]:
251+
) -> ApiResponse[Any]:
252252
if headers:
253253
request_headers = self._headers.copy()
254254
request_headers.update(headers)
@@ -327,18 +327,18 @@ def _perform_request(
327327
if method == "HEAD":
328328
response = HeadApiResponse(meta=meta)
329329
elif isinstance(resp_body, dict):
330-
response = ObjectApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
330+
response = ObjectApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
331331
elif isinstance(resp_body, list):
332-
response = ListApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
332+
response = ListApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
333333
elif isinstance(resp_body, str):
334334
response = TextApiResponse( # type: ignore[assignment]
335-
raw=resp_body,
335+
body=resp_body,
336336
meta=meta,
337337
)
338338
elif isinstance(resp_body, bytes):
339-
response = BinaryApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
339+
response = BinaryApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
340340
else:
341-
response = ApiResponse(raw=resp_body, meta=meta) # type: ignore[assignment]
341+
response = ApiResponse(body=resp_body, meta=meta) # type: ignore[assignment]
342342

343343
return response
344344

elasticsearch/helpers/actions.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _process_bulk_chunk(
347347
)
348348
else:
349349
gen = _process_bulk_chunk_success(
350-
resp=resp.raw,
350+
resp=resp.body,
351351
bulk_data=bulk_data,
352352
ignore_status=ignore_status,
353353
raise_on_error=raise_on_error,
@@ -704,19 +704,19 @@ def pop_transport_kwargs(kw: MutableMapping[str, Any]) -> Dict[str, Any]:
704704
search_kwargs["size"] = size
705705
resp = client.search(body=query, **search_kwargs) # type: ignore[call-arg]
706706

707-
scroll_id = resp.raw.get("_scroll_id")
707+
scroll_id = resp.get("_scroll_id")
708708
scroll_transport_kwargs = pop_transport_kwargs(scroll_kwargs)
709709
if scroll_transport_kwargs:
710710
scroll_client = client.options(**scroll_transport_kwargs)
711711
else:
712712
scroll_client = client
713713

714714
try:
715-
while scroll_id and resp.raw["hits"]["hits"]:
716-
yield from resp.raw["hits"]["hits"]
715+
while scroll_id and resp["hits"]["hits"]:
716+
yield from resp["hits"]["hits"]
717717

718718
# Default to 0 if the value isn't included in the response
719-
shards_info: Dict[str, int] = resp.raw["_shards"]
719+
shards_info: Dict[str, int] = resp["_shards"]
720720
shards_successful = shards_info.get("successful", 0)
721721
shards_skipped = shards_info.get("skipped", 0)
722722
shards_total = shards_info.get("total", 0)
@@ -743,7 +743,7 @@ def pop_transport_kwargs(kw: MutableMapping[str, Any]) -> Dict[str, Any]:
743743
resp = scroll_client.scroll(
744744
scroll_id=scroll_id, scroll=scroll, **scroll_kwargs
745745
)
746-
scroll_id = resp.raw.get("_scroll_id")
746+
scroll_id = resp.get("_scroll_id")
747747

748748
finally:
749749
if scroll_id and clear_scroll:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
if package == package_name or package.startswith(package_name + ".")
5252
]
5353

54-
install_requires = ["elastic-transport>=8.0.0a1,<9"]
54+
install_requires = ["elastic-transport>=8.0.0a7,<9"]
5555
async_requires = ["aiohttp>=3,<4"]
5656

5757
setup(

test_elasticsearch/test_async/test_server/test_helpers.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ async def __call__(self, *args, **kwargs):
425425
self.calls.append((args, kwargs))
426426
if len(self.calls) == 1:
427427
return ObjectApiResponse(
428-
raw={
428+
body={
429429
"_scroll_id": "dummy_id",
430430
"_shards": {"successful": 4, "total": 5, "skipped": 0},
431431
"hits": {"hits": [{"scroll_data": 42}]},
@@ -434,7 +434,7 @@ async def __call__(self, *args, **kwargs):
434434
)
435435
elif len(self.calls) == 2:
436436
return ObjectApiResponse(
437-
raw={
437+
body={
438438
"_scroll_id": "dummy_id",
439439
"_shards": {"successful": 4, "total": 5, "skipped": 0},
440440
"hits": {"hits": []},
@@ -549,7 +549,7 @@ async def test_initial_search_error(self, async_client, scan_teardown):
549549
"search",
550550
MockResponse(
551551
ObjectApiResponse(
552-
raw={
552+
body={
553553
"_scroll_id": "dummy_id",
554554
"_shards": {"successful": 4, "total": 5, "skipped": 0},
555555
"hits": {"hits": [{"search_data": 1}]},
@@ -576,7 +576,7 @@ async def test_initial_search_error(self, async_client, scan_teardown):
576576
"search",
577577
MockResponse(
578578
ObjectApiResponse(
579-
raw={
579+
body={
580580
"_scroll_id": "dummy_id",
581581
"_shards": {"successful": 4, "total": 5, "skipped": 0},
582582
"hits": {"hits": [{"search_data": 1}]},
@@ -606,7 +606,7 @@ async def test_no_scroll_id_fast_route(self, async_client, scan_teardown):
606606
), patch.object(async_client, "scroll") as scroll_mock, patch.object(
607607
async_client,
608608
"search",
609-
MockResponse(ObjectApiResponse(raw={"no": "_scroll_id"}, meta=None)),
609+
MockResponse(ObjectApiResponse(body={"no": "_scroll_id"}, meta=None)),
610610
), patch.object(
611611
async_client, "clear_scroll"
612612
) as clear_mock:
@@ -720,7 +720,7 @@ async def test_scan_auth_kwargs_forwarded(
720720
"search",
721721
return_value=MockResponse(
722722
ObjectApiResponse(
723-
raw={
723+
body={
724724
"_scroll_id": "scroll_id",
725725
"_shards": {"successful": 5, "total": 5, "skipped": 0},
726726
"hits": {"hits": [{"search_data": 1}]},
@@ -734,7 +734,7 @@ async def test_scan_auth_kwargs_forwarded(
734734
"scroll",
735735
return_value=MockResponse(
736736
ObjectApiResponse(
737-
raw={
737+
body={
738738
"_scroll_id": "scroll_id",
739739
"_shards": {"successful": 5, "total": 5, "skipped": 0},
740740
"hits": {"hits": []},
@@ -773,7 +773,7 @@ async def test_scan_auth_kwargs_favor_scroll_kwargs_option(
773773
"search",
774774
return_value=MockResponse(
775775
ObjectApiResponse(
776-
raw={
776+
body={
777777
"_scroll_id": "scroll_id",
778778
"_shards": {"successful": 5, "total": 5, "skipped": 0},
779779
"hits": {"hits": [{"search_data": 1}]},
@@ -787,7 +787,7 @@ async def test_scan_auth_kwargs_favor_scroll_kwargs_option(
787787
"scroll",
788788
return_value=MockResponse(
789789
ObjectApiResponse(
790-
raw={
790+
body={
791791
"_scroll_id": "scroll_id",
792792
"_shards": {"successful": 5, "total": 5, "skipped": 0},
793793
"hits": {"hits": []},

test_elasticsearch/test_async/test_server/test_mapbox_vector_tile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ async def test_mapbox_vector_tile_response(elasticsearch_url, mvt_setup, ca_cert
140140
)
141141

142142
assert resp.meta.status == 200
143-
assert isinstance(resp.raw, bytes)
143+
assert isinstance(resp.body, bytes)
144144

145145
# Decode the binary as MVT
146-
tile = mapbox_vector_tile.decode(resp.raw)
146+
tile = mapbox_vector_tile.decode(resp.body)
147147

148148
# Assert some general things about the structure, mostly we want
149149
# to know that we got back a valid MVT.

test_elasticsearch/test_async/test_server/test_rest_api_spec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async def run_do(self, action):
174174
warnings.simplefilter("always", category=ElasticsearchWarning)
175175
with warnings.catch_warnings(record=True) as caught_warnings:
176176
try:
177-
self.last_response = (await api(**args)).raw
177+
self.last_response = (await api(**args)).body
178178
except Exception as e:
179179
self._skip_intentional_type_errors(e)
180180
if not catch:

test_elasticsearch/test_server/test_mapbox_vector_tile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ def test_mapbox_vector_tile_response(
142142
)
143143

144144
assert resp.meta.status == 200
145-
assert isinstance(resp.raw, bytes)
145+
assert isinstance(resp.body, bytes)
146146

147147
# Decode the binary as MVT
148-
tile = mapbox_vector_tile.decode(resp.raw)
148+
tile = mapbox_vector_tile.decode(resp.body)
149149

150150
# Assert some general things about the structure, mostly we want
151151
# to know that we got back a valid MVT.

test_elasticsearch/test_server/test_responses.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
def test_text_response(sync_client):
2020
resp = sync_client.cat.tasks()
2121
assert resp.meta.status == 200
22-
assert isinstance(resp.raw, str)
23-
assert str(resp.raw) == str(resp)
22+
assert isinstance(resp.body, str)
23+
assert str(resp.body) == str(resp)
2424

2525

2626
def test_object_response(sync_client):
2727
resp = sync_client.search(size=1)
28-
assert isinstance(resp.raw, dict)
29-
assert set(resp) == set(resp.raw)
28+
assert isinstance(resp.body, dict)
29+
assert set(resp) == set(resp.body)
3030
assert resp.items()
3131
assert resp.keys()
32-
assert str(resp) == str(resp.raw)
33-
assert resp["hits"] == resp.raw["hits"]
32+
assert str(resp) == str(resp.body)
33+
assert resp["hits"] == resp.body["hits"]
3434
assert type(resp.copy()) is dict
3535

3636

3737
def test_exists_response(sync_client):
3838
resp = sync_client.indices.exists(index="no")
39-
assert resp.raw is False
39+
assert resp.body is False
4040
assert not resp
4141
if resp:
4242
assert False, "Didn't evaluate to 'False'"

test_elasticsearch/test_server/test_rest_api_spec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def run_do(self, action):
276276
warnings.simplefilter("always", category=ElasticsearchWarning)
277277
with warnings.catch_warnings(record=True) as caught_warnings:
278278
try:
279-
self.last_response = api(**args).raw
279+
self.last_response = api(**args).body
280280
except Exception as e:
281281
self._skip_intentional_type_errors(e)
282282
if not catch:

0 commit comments

Comments
 (0)