@@ -298,7 +298,8 @@ def _merge_kwargs_no_duplicates(kwargs: Dict[str, Any], values: Dict[str, Any])
298
298
299
299
def _merge_body_fields_no_duplicates (
300
300
body : _TYPE_BODY , kwargs : Dict [str , Any ], body_fields : Tuple [str , ...]
301
- ) -> None :
301
+ ) -> bool :
302
+ mixed_body_and_params = False
302
303
for key in list (kwargs .keys ()):
303
304
if key in body_fields :
304
305
if isinstance (body , (str , bytes )):
@@ -315,11 +316,13 @@ def _merge_body_fields_no_duplicates(
315
316
warnings .warn (
316
317
f"Received '{ key } ' via a specific parameter in the presence of a "
317
318
"'body' parameter, which is deprecated and will be removed in a future "
318
- "version. Instead, use only 'body' or only specific paremeters ." ,
319
+ "version. Instead, use only 'body' or only specific parameters ." ,
319
320
category = DeprecationWarning ,
320
321
stacklevel = warn_stacklevel (),
321
322
)
322
323
body [key ] = kwargs .pop (key )
324
+ mixed_body_and_params = True
325
+ return mixed_body_and_params
323
326
324
327
325
328
def _rewrite_parameters (
@@ -401,6 +404,7 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
401
404
not ignore_deprecated_options or "body" not in ignore_deprecated_options
402
405
):
403
406
body : Optional [_TYPE_BODY ] = kwargs .pop ("body" )
407
+ mixed_body_and_params = False
404
408
if body is not None :
405
409
if body_name :
406
410
if body_name in kwargs :
@@ -411,11 +415,27 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
411
415
"issues/1698 for more information"
412
416
)
413
417
kwargs [body_name ] = body
414
-
415
418
elif body_fields is not None :
416
- _merge_body_fields_no_duplicates (body , kwargs , body_fields )
419
+ mixed_body_and_params = _merge_body_fields_no_duplicates (
420
+ body , kwargs , body_fields
421
+ )
417
422
kwargs ["body" ] = body
418
423
424
+ if parameter_aliases and not isinstance (body , (str , bytes )):
425
+ for alias , rename_to in parameter_aliases .items ():
426
+ if rename_to in body :
427
+ body [alias ] = body .pop (rename_to )
428
+ # If body and params are mixed, the alias may come from a param,
429
+ # in which case the warning below will not make sense.
430
+ if not mixed_body_and_params :
431
+ warnings .warn (
432
+ f"Using '{ rename_to } ' alias in 'body' is deprecated and will be removed "
433
+ f"in a future version of elasticsearch-py. Use '{ alias } ' directly instead. "
434
+ "See https://github.com/elastic/elasticsearch-py/issues/1698 for more information" ,
435
+ category = DeprecationWarning ,
436
+ stacklevel = 2 ,
437
+ )
438
+
419
439
if parameter_aliases :
420
440
for alias , rename_to in parameter_aliases .items ():
421
441
try :
0 commit comments