Skip to content

Commit

Permalink
If ignore=404 is passed to .get, return None on miss
Browse files Browse the repository at this point in the history
Fixes #88
  • Loading branch information
honzakral committed May 11, 2015
1 parent 40d8c27 commit 8ae9227
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions elasticsearch_dsl/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def get(cls, id, using=None, index=None, **kwargs):
id=id,
**kwargs
)
if not doc['found']:
return None
return cls.from_es(doc)

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions test_elasticsearch_dsl/test_integration/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def test_get_raises_404_on_non_existent_id(data_client):
with raises(NotFoundError):
Repository.get('elasticsearch-dsl-php')

def test_get_returns_none_if_404_ignored(data_client):
assert None is Repository.get('elasticsearch-dsl-php', ignore=404)

def test_get(data_client):
elasticsearch_repo = Repository.get('elasticsearch-dsl-py')

Expand Down

0 comments on commit 8ae9227

Please sign in to comment.