Regression in 1.3.7 when indexing a document with a existing id
romibuzi opened this issue · 0 comments
romibuzi commented
Hi,
first of all thank you for this package. I have noticed there may have been a regression introduced in version 1.3.7
when indexing a document with a existing id
.
Here is a basic test to reproduce the problem
test_index.py
:
import unittest
from datetime import datetime
from unittest import TestCase
from elasticmock import FakeElasticsearch
class TestIndexing(TestCase):
def test_insert_document(self):
es = FakeElasticsearch()
doc = {
'author': 'kimchy',
'text': 'Elasticsearch: cool. bonsai cool.',
'timestamp': datetime.now(),
}
res = es.index(index="test-index", id=1, doc_type="_doc", body=doc)
self.assertEqual(res["_id"], 1)
if __name__ == "__main__":
unittest.main()
With elasticmock==1.3.6
this test runs fine, but with 1.3.7
I get the following result :
$ python test_index.py
E
======================================================================
ERROR: test_insert_document (__main__.TestIndexing)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_index.py", line 16, in test_insert_document
res = es.index(index="test-index", id=1, doc_type="_doc", body=doc)
File "/Users/romain/Workspaces/Python/test-elasticmock/venv/lib/python3.7/site-packages/elasticsearch/client/utils.py", line 84, in _wrapped
return func(*args, params=params, **kwargs)
File "/Users/romain/Workspaces/Python/test-elasticmock/venv/lib/python3.7/site-packages/elasticmock/fake_elasticsearch.py", line 56, in index
doc = self.get(index, id, doc_type)
File "/Users/romain/Workspaces/Python/test-elasticmock/venv/lib/python3.7/site-packages/elasticsearch/client/utils.py", line 84, in _wrapped
return func(*args, params=params, **kwargs)
File "/Users/romain/Workspaces/Python/test-elasticmock/venv/lib/python3.7/site-packages/elasticmock/fake_elasticsearch.py", line 152, in get
raise NotFoundError(404, json.dumps(error_data))
elasticsearch.exceptions.NotFoundError: NotFoundError(404, '{"_index": "test-index", "_type": "_doc", "_id": 1, "found": false}')
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
It appears that elasticmock is trying to get it from its document list, but as it's not yet created it fails with a NotFoundError