Skip to content

fix application crushes with error in AsyncSearch().count() method #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: async-io
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion elasticsearch_dsl/_async/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ async def count(self):

d = self.to_dict(count=True)
# TODO: failed shards detection
return await es.count(index=self._index, body=d, **self._params)["count"]
resp_count = await es.count(index=self._index, body=d, **self._params)
return resp_count["count"]

async def execute(self, ignore_cache=False):
"""
Expand Down
3 changes: 2 additions & 1 deletion elasticsearch_dsl/_sync/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ def count(self):

d = self.to_dict(count=True)
# TODO: failed shards detection
return es.count(index=self._index, body=d, **self._params)["count"]
resp_count = es.count(index=self._index, body=d, **self._params)
return resp_count["count"]

def execute(self, ignore_cache=False):
"""
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch_dsl/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def _deserialize(self, data):
if isinstance(data, date):
return data
if isinstance(data, integer_types):
# Divide by a float to preserve milliseconds on the datetime.
return datetime.utcfromtimestamp(data / 1000.0)
# Not needed divide by a float to preserve milliseconds on the datetime, because 'data' already in the required format.
return datetime.utcfromtimestamp(data)

raise ValidationException("Could not parse date from the value (%r)" % data)

Expand Down