Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vocab_file should be saved before loading #217

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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