Skip to content

Commit

Permalink
fix: vocab_file should be saved before loading
Browse files Browse the repository at this point in the history
  • Loading branch information
yangnoahlin committed Oct 22, 2024
1 parent 6be8ab2 commit 461af16
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 461af16

Please sign in to comment.