Commit 036e6b23 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed endless recursion in archive access with missing entry. #292

parent d2982bf5
......@@ -360,7 +360,7 @@ class ArchiveReader(ArchiveObject):
if positions is None:
r_start = 0
r_end = self._n_toc
while positions is None:
while positions is None and len(self._toc) < self._n_toc:
i_block = r_start + math.floor((r_end - r_start) / 2)
first, last = self._load_toc_block(i_block)
if key < first:
......@@ -371,6 +371,9 @@ class ArchiveReader(ArchiveObject):
positions = self._toc.get(key)
break
if positions is None:
raise KeyError(key)
toc_position, data_position = positions
else:
......
......@@ -6,6 +6,8 @@ from io import BytesIO
from nomad import utils
from nomad.archive import TOCPacker, write_archive, read_archive, ArchiveReader, query_archive
from .utils import assert_exception
def create_example_uuid(index: int = 0):
return ('{:%dd}' % utils.default_hash_len).format(index)
......@@ -145,6 +147,15 @@ def test_read_archive_single(example_uuid, example_entry, use_blocked_toc):
assert data[example_uuid]['run'].to_dict() == example_entry['run']
assert data[example_uuid].to_dict() == example_entry
with assert_exception(KeyError):
data['does not exist']
with assert_exception(KeyError):
data[example_uuid]['does not exist']
with assert_exception(IndexError):
data[example_uuid]['run']['system'][2]
@pytest.mark.parametrize('use_blocked_toc', [False, True])
def test_read_archive_multi(example_uuid, example_entry, use_blocked_toc):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment