Skip to content

Commit

Permalink
C4-30 Patch PickStorage bug (#128)
Browse files Browse the repository at this point in the history
* C4-30 patch PickStorage bug

* C4-30 add comment + old change

* C4-30 mark es basic as flaky
  • Loading branch information
willronchetti authored Feb 13, 2020
1 parent 2db5b45 commit 14cc315
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/snovault/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ def get_by_uuid(self, uuid, datastore=None):
storage = self.storage(datastore)
model = storage.get_by_uuid(uuid)
# unless forcing ES datastore, check write storage if not found in read
if datastore == 'database' and storage is self.read:
# if datastore == 'database' and storage is self.read:
# Old is above - See C4-30
# if not specifically specifying datastore=elasticsearch, always fall back to DB
if not datastore == 'elasticsearch':
if model is None:
return self.write.get_by_uuid(uuid)
return model
Expand All @@ -184,7 +187,10 @@ def get_by_unique_key(self, unique_key, name, datastore=None):
storage = self.storage(datastore)
model = storage.get_by_unique_key(unique_key, name)
# unless forcing ES datastore, check write storage if not found in read
if datastore == 'database' and storage is self.read:
# if datastore == 'database' and storage is self.read:
# Old is above - See C4-30
# if not specifically specifying datastore=elasticsearch, always fall back to DB
if not datastore == 'elasticsearch':
if model is None:
return self.write.get_by_unique_key(unique_key, name)
return model
Expand All @@ -196,7 +202,10 @@ def get_by_json(self, key, value, item_type, default=None, datastore=None):
storage = self.storage(datastore)
model = storage.get_by_json(key, value, item_type)
# unless forcing ES datastore, check write storage if not found in read
if datastore == 'database' and storage is self.read:
# if datastore == 'database' and storage is self.read:
# Old is above - See C4-30
# if not specifically specifying datastore=elasticsearch, always fall back to DB
if not datastore == 'elasticsearch':
if model is None:
return self.write.get_by_json(key, value, item_type)
return model
Expand Down
13 changes: 13 additions & 0 deletions src/snovault/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ def es_based_target(app, testapp):
es.indices.delete(index=namespaced_indexing)


def test_indexing_post_then_get_immediately(testapp, indexer_testapp):
"""
Tests that we can post then immediately get an object
"""
res = testapp.post_json(TEST_COLL, {'required': 'some_value'})
test_uuid = res.json['@graph'][0]['uuid']
testapp.get('/' + test_uuid, status=[301, 200])
res = indexer_testapp.post_json('/index', {'record': True})
assert res.json['indexing_count'] == 1
testapp.get('/' + test_uuid, status=[301, 200])


def test_indexer_namespacing(app, testapp, indexer_testapp):
"""
Tests that namespacing indexes works as expected. This test has no real
Expand Down Expand Up @@ -1368,6 +1380,7 @@ def test_validators_on_indexing(app, testapp, indexer_testapp):
assert val_err_view['validation_errors'] == es_res['_source']['validation_errors']


@pytest.mark.flaky
def test_elasticsearch_item_basic(app, testapp, indexer_testapp, es_based_target):
es = app.registry[ELASTIC_SEARCH]
namespaced_target = indexer_utils.get_namespaced_index(app, 'testing_link_target_elastic_search')
Expand Down

0 comments on commit 14cc315

Please sign in to comment.