Skip to content

Commit

Permalink
Ignore 404 on fetch to avoid a log message
Browse files Browse the repository at this point in the history
Otherwise, elasticsearch will emit a log message even though we
ignore the exception.
  • Loading branch information
tilgovi committed Feb 11, 2015
1 parent 9347dfe commit 8ce3370
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 6 additions & 7 deletions annotator/elasticsearch.py
Expand Up @@ -131,13 +131,12 @@ def drop_all(cls):
# already define that method name.
@classmethod
def fetch(cls, id):
try:
doc = cls.es.conn.get(index=cls.es.index,
doc_type=cls.__type__,
id=id)
except elasticsearch.exceptions.NotFoundError:
return None
return cls(doc['_source'], id=id)
doc = cls.es.conn.get(index=cls.es.index,
doc_type=cls.__type__,
ignore=404,
id=id)
if doc.get('found', True):
return cls(doc['_source'], id=id)

@classmethod
def _build_query(cls, query=None, offset=None, limit=None, sort=None, order=None):
Expand Down
4 changes: 1 addition & 3 deletions tests/test_elasticsearch.py
Expand Up @@ -57,9 +57,7 @@ def test_fetch(self, es_mock):
@patch('annotator.elasticsearch.elasticsearch.Elasticsearch')
def test_fetch_not_found(self, es_mock):
conn = es_mock.return_value
def raise_exc(*args, **kwargs):
raise elasticsearch.exceptions.NotFoundError('foo')
conn.get.side_effect = raise_exc
conn.get.return_value = {'found': False}
o = self.Model.fetch(123)
assert_equal(o, None)

Expand Down

0 comments on commit 8ce3370

Please sign in to comment.