From 52774b33043c59bfa4c3c60df5f0369c86047b40 Mon Sep 17 00:00:00 2001 From: Tom Searle Date: Wed, 25 Sep 2024 12:56:12 +0100 Subject: [PATCH] CU-8695y7r4y: Fix vocab path check, also included edge case error IndexErrors on docs with no entities --- webapp/api/api/models.py | 2 +- webapp/api/api/utils.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/webapp/api/api/models.py b/webapp/api/api/models.py index a10ce47..f69385c 100644 --- a/webapp/api/api/models.py +++ b/webapp/api/api/models.py @@ -137,7 +137,7 @@ def save(self, *args, skip_load=False, **kwargs): # load the Vocab, and raise if this fails if not skip_load: try: - Vocab.load(self.vocab_file) + Vocab.load(self.vocab_file.path) except Exception as exc: raise MedCATLoadException(f'Failed to load Vocab from {self.vocab_file}, ' f'check if this Vocab file successfully loads elsewhere') from exc diff --git a/webapp/api/api/utils.py b/webapp/api/api/utils.py index 41039df..03354f2 100644 --- a/webapp/api/api/utils.py +++ b/webapp/api/api/utils.py @@ -47,8 +47,9 @@ def add_annotations(spacy_doc, user, project, document, existing_annotations, ca for task_name in spacy_doc._.ents[0]._.meta_anns.keys()} metataskvals2obj = {task_name: {v.name: v for v in MetaTask.objects.get(name=task_name).values.all()} for task_name in spacy_doc._.ents[0]._.meta_anns.keys()} - except AttributeError: - # ignore meta_anns that are not present - i.e. non model pack preds, + except (AttributeError, IndexError): + # IndexError: ignore if there are no annotations in this doc + # AttributeError: ignore meta_anns that are not present - i.e. non model pack preds # or model pack preds with no meta_anns metatask2obj = {} metataskvals2obj = {}