Skip to content
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

Regression in 1.3.7 when indexing a document with a existing id #34

Closed
romibuzi opened this issue Feb 13, 2020 · 0 comments
Closed

Regression in 1.3.7 when indexing a document with a existing id #34

romibuzi opened this issue Feb 13, 2020 · 0 comments

Comments

@romibuzi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant