Skip to content

Commit

Permalink
Merge pull request #171 from adisbladis/master
Browse files Browse the repository at this point in the history
Change document.save/delete to raise ValidationError on no index
  • Loading branch information
honzakral committed Jun 8, 2015
2 parents 09c63c6 + 113d15c commit dc3021d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions elasticsearch_dsl/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .result import ResultMeta
from .search import Search
from .connections import connections
from .exceptions import ValidationException

DOC_META_FIELDS = frozenset((
'id', 'parent', 'routing', 'timestamp', 'ttl', 'version', 'version_type'
Expand Down Expand Up @@ -165,7 +166,7 @@ def delete(self, using=None, index=None, **kwargs):
if index is None:
index = getattr(self.meta, 'index', self._doc_type.index)
if index is None:
raise #XXX - no index
raise ValidationException('No index')
# extract parent, routing etc from meta
doc_meta = dict(
(k, self.meta[k])
Expand Down Expand Up @@ -199,7 +200,7 @@ def save(self, using=None, index=None, **kwargs):
if index is None:
index = getattr(self.meta, 'index', self._doc_type.index)
if index is None:
raise #XXX - no index
raise ValidationException('No index')
# extract parent, routing etc from meta
doc_meta = dict(
(k, self.meta[k])
Expand Down
10 changes: 10 additions & 0 deletions test_elasticsearch_dsl/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,13 @@ def test_meta_fields_can_be_accessed_directly_with_underscore():
assert md.meta.id == 42
assert md._id == 42
assert md.meta.parent is md._parent is p

def test_save_no_index(mock_client):
md = MyDoc()
with raises(ValidationException):
md.save(using='mock')

def test_delete_no_index(mock_client):
md = MyDoc()
with raises(ValidationException):
md.delete(using='mock')

0 comments on commit dc3021d

Please sign in to comment.