Skip to content

Commit

Permalink
Fixed asynchronous search query to_dict method
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-social committed Nov 14, 2019
1 parent c1669e0 commit 2c111bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions elasticmagic/ext/asyncio/search.py
Expand Up @@ -5,6 +5,10 @@ class AsyncSearchQuery(BaseSearchQuery):
"""Asynchronous version of the :class:`.SearchQuery`
"""

async def to_dict(self, compiler=None):
compiler = compiler or await self.get_compiler()
return compiler.compiled_query(self).body

async def get_compiler(self):
return await self._index_or_cluster.get_compiler()

Expand Down
14 changes: 7 additions & 7 deletions elasticmagic/search.py
Expand Up @@ -713,13 +713,6 @@ def get_compiler_context(self):

get_context = get_compiler_context

def to_dict(self, compiler=None):
"""Compiles the query and returns python dictionary that can be
serialized to json.
"""
compiler = compiler or self.get_compiler()
return compiler.compiled_query(self).body

def slice(self, offset, limit):
"""Applies offset and limit to the query."""
sliced_query, _ = self._prepare_slice(slice(offset, limit))
Expand Down Expand Up @@ -793,6 +786,13 @@ def get_compiler(self):
def get_query_compiler(self):
return self.get_compiler().compiled_query

def to_dict(self, compiler=None):
"""Compiles the query and returns python dictionary that can be
serialized to json.
"""
compiler = compiler or self.get_compiler()
return compiler.compiled_query(self).body

def get_result(self):
"""Executes current query and returns processed :class:`SearchResult`
object. Caches result so subsequent calls with the same search query
Expand Down
12 changes: 12 additions & 0 deletions tests_integ/asyncio/test_search.py
Expand Up @@ -3,6 +3,18 @@
from .conftest import Car


@pytest.mark.asyncio
async def test_to_dict(es_index, cars):
sq = (
es_index.search_query()
.limit(1)
)

assert await sq.to_dict() == {
'size': 1
}


@pytest.mark.asyncio
async def test_get_result(es_index, cars):
sq = (
Expand Down

0 comments on commit 2c111bd

Please sign in to comment.