diff --git a/nomad/parsing/parser.py b/nomad/parsing/parser.py index 49c230b9aa046447ef9a6ac64ee8c49f731d4e6f..09a876b49424c1758ff288cd83918f60a212cdf0 100644 --- a/nomad/parsing/parser.py +++ b/nomad/parsing/parser.py @@ -392,6 +392,11 @@ class MatchingParserInterface(MatchingParser): self._parser_class_name = parser_class_name self._mainfile_parser = None + def new_parser_instance(self): + ''' Forgets the existing parser instance and forces the creation of a new one. ''' + self._mainfile_parser = None + return self._mainfile_parser + @property def mainfile_parser(self): if self._mainfile_parser is None: diff --git a/nomad/processing/data.py b/nomad/processing/data.py index 194a76833475d73f2ca5c6329b37497e0223c812..415ea57472c692db0c4cc7197f30f85e7507e995 100644 --- a/nomad/processing/data.py +++ b/nomad/processing/data.py @@ -1140,7 +1140,7 @@ class Entry(Proc): if not config.process.reuse_parser: if isinstance(parser, parsing.MatchingParserInterface): try: - parser = parser.__class__() + parser.new_parser_instance() except Exception as e: raise ProcessFailure( 'could not re-create parser instance', diff --git a/tests/processing/test_data.py b/tests/processing/test_data.py index 17ba7eb4b11554e1f349b8397eeda38a12e6ef39..7bd62adbbc2a55e920f047e74179ce8405779be7 100644 --- a/tests/processing/test_data.py +++ b/tests/processing/test_data.py @@ -536,6 +536,20 @@ def test_re_process_match(non_empty_processed, published, monkeypatch, no_warn): assert not upload.with_embargo +@pytest.mark.parametrize('reuse_parser', [False, True]) +def test_reuse_parser(monkeypatch, tmp, test_user, proc_infra, reuse_parser, no_warn): + upload_path = os.path.join(tmp, 'example_upload.zip') + with zipfile.ZipFile(upload_path, 'w') as zf: + zf.write('tests/data/parsers/vasp/vasp.xml', 'one/run.vasp.xml') + zf.write('tests/data/parsers/vasp/vasp.xml', 'two/run.vasp.xml') + + monkeypatch.setattr('nomad.config.process.reuse_parser', reuse_parser) + upload = run_processing(('example_upload', upload_path,), test_user) + + assert upload.total_entries_count == 2 + assert upload.process_status == 'SUCCESS' + + @pytest.mark.parametrize('args', [ pytest.param( dict(