Skip to content

Commit

Permalink
CU-8695ydumw: save cdb_file so it gets a storage generated path befor…
Browse files Browse the repository at this point in the history
…e checking validity
  • Loading branch information
tomolopolis committed Sep 25, 2024
1 parent b6a58be commit d30cf36
Showing 1 changed file with 6 additions and 5 deletions.
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

0 comments on commit d30cf36

Please sign in to comment.