File tree 2 files changed +26
-1
lines changed
elasticsearch/_sync/client
test_elasticsearch/test_client
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -411,11 +411,21 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
411
411
"issues/1698 for more information"
412
412
)
413
413
kwargs [body_name ] = body
414
-
415
414
elif body_fields is not None :
416
415
_merge_body_fields_no_duplicates (body , kwargs , body_fields )
417
416
kwargs ["body" ] = body
418
417
418
+ if parameter_aliases and not isinstance (body , (str , bytes )):
419
+ for alias , rename_to in parameter_aliases .items ():
420
+ if rename_to in body :
421
+ warnings .warn (
422
+ f"Using '{ rename_to } ' alias in 'body' is deprecated and will be removed in a future version of elasticsearch-py. "
423
+ f"Use '{ alias } ' directly instead." ,
424
+ category = DeprecationWarning ,
425
+ stacklevel = 2 ,
426
+ )
427
+ body [alias ] = body .pop (rename_to )
428
+
419
429
if parameter_aliases :
420
430
for alias , rename_to in parameter_aliases .items ():
421
431
try :
Original file line number Diff line number Diff line change @@ -238,6 +238,21 @@ def test_parameter_aliases(self):
238
238
self .wrapped_func_aliases (source = ["key3" ])
239
239
assert self .calls [- 1 ] == ((), {"source" : ["key3" ]})
240
240
241
+ def test_parameter_aliases_body (self ):
242
+ with pytest .warns (
243
+ DeprecationWarning ,
244
+ match = (
245
+ "Using 'source' alias in 'body' is deprecated and will be removed in a future version of elasticsearch-py. "
246
+ "Use '_source' directly instead."
247
+ ),
248
+ ):
249
+ self .wrapped_func_aliases (body = {"source" : ["key4" ]})
250
+
251
+ # using the correct name does not warn
252
+ with warnings .catch_warnings ():
253
+ warnings .simplefilter ("error" )
254
+ self .wrapped_func_aliases (body = {"_source" : ["key4" ]})
255
+
241
256
@pytest .mark .parametrize ("client_cls" , [Elasticsearch , AsyncElasticsearch ])
242
257
def test_positional_argument_error (self , client_cls ):
243
258
client = client_cls ("https://localhost:9200" )
You can’t perform that action at this time.
0 commit comments