Skip to content

Commit

Permalink
🎨 Removed deprecated body param
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbadyal committed Jan 26, 2024
1 parent c16329c commit 37528e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion esxport/click_opt/click_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Json(ParamType):
def convert(self: Self, value: Any, param: Parameter | None, ctx: Context | None) -> dict[str, Any]:
"""Convert input to json."""
try:
return json.loads(value) # type: ignore[no-any-return]
return value if isinstance(value, dict) else json.loads(value) # type: ignore[no-any-return]
except json.JSONDecodeError as exc:
self.fail(invalid_query_format.format(value=value, exc=exc), param, ctx)

Expand Down
6 changes: 4 additions & 2 deletions esxport/esxport.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from esxport.strings import index_not_found, meta_field_not_found, output_fields, sorting_by, using_indexes, using_query
from esxport.writer import Writer

from .click_opt.click_custom import Json

if TYPE_CHECKING:
from typing_extensions import Self

Expand Down Expand Up @@ -87,7 +89,7 @@ def _prepare_search_query(self: Self) -> None:
"scroll": self.scroll_time,
"size": self.opts.scroll_size,
"terminate_after": self.opts.max_results,
"body": self.opts.query,
"query": Json().convert(self.opts.query, None, None)["query"],
}
if self.opts.sort:
self.search_args["sort"] = self.opts.sort
Expand All @@ -97,7 +99,7 @@ def _prepare_search_query(self: Self) -> None:

if self.opts.debug:
logger.debug(using_indexes.format(indexes={", ".join(self.opts.index_prefixes)}))
query = json.dumps(self.opts.query)
query = json.dumps(self.opts.query, default=str)
logger.debug(using_query.format(query={query}))
logger.debug(output_fields.format(fields={", ".join(self.opts.fields)}))
logger.debug(sorting_by.format(sort=self.opts.sort))
Expand Down
3 changes: 2 additions & 1 deletion test/esxport/_prepare_search_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def test_query(self: Self, _: Any, esxport_obj: EsXport) -> None:
"""
expected_query: dict[str, Any] = {"query": {"match_all": {}}}
esxport_obj.opts.query = expected_query
actual_query = expected_query["query"]

esxport_obj._prepare_search_query()
assert esxport_obj.search_args["body"] == expected_query
assert esxport_obj.search_args["query"] == actual_query

def test_terminate_after(self: Self, _: Any, esxport_obj: EsXport) -> None:
"""Arr, matey!.
Expand Down

0 comments on commit 37528e8

Please sign in to comment.