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

CU-8695ydumw: save cdb_file so it gets a storage generated path befor… #212

Merged
merged 1 commit into from
Sep 25, 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
11 changes: 6 additions & 5 deletions webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@ def from_db(cls, db, field_names, values):
return inst

def save(self, *args, skip_load=False, **kwargs):
# load the CDB, and raise if this fails.
if self.__cdb_field_name is not None and self.__cdb_field_name != self.cdb_file.name:
raise ValidationError('Cannot change file path of existing CDB.')
else:
super().save(*args, **kwargs)
# load the CDB, and raise if this fails - must be saved first so storage handler can rename path if name clashes
if not skip_load:
try:
CDB.load(self.cdb_file.path)
except Exception as exc:
raise MedCATLoadException(f'Failed to load Concept DB from {self.cdb_file}, '
f'check if this CDB file successfully loads elsewhere') from exc
if self.__cdb_field_name is not None and self.__cdb_field_name != self.cdb_file.name:
raise ValidationError('Cannot change file path of existing CDB.')
else:
super().save(*args, **kwargs)


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