Skip to content

Commit

Permalink
Merge pull request #212 from CogStack/cdb-verification-fix
Browse files Browse the repository at this point in the history
CU-8695ydumw: save cdb_file so it gets a storage generated path befor…
  • Loading branch information
tomolopolis authored Sep 25, 2024
2 parents b6a58be + d30cf36 commit 562029c
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 562029c

Please sign in to comment.