Skip to content

Commit

Permalink
Merge pull request #217 from yangnoahlin/master
Browse files Browse the repository at this point in the history
fix: vocab_file should be saved before loading
  • Loading branch information
tomolopolis authored Oct 30, 2024
2 parents 6be8ab2 + 461af16 commit d1865f6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ class Vocabulary(models.Model):
vocab_file = models.FileField()

def save(self, *args, skip_load=False, **kwargs):
super().save(*args, **kwargs)

# load the Vocab, and raise if this fails
if not skip_load:
try:
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
super().save(*args, **kwargs)

def __str__(self):
return str(self.vocab_file.name)
Expand Down

0 comments on commit d1865f6

Please sign in to comment.