From d30cf36bf38f78cba7073f7297a11cc2b363a57b Mon Sep 17 00:00:00 2001 From: tomolopolis Date: Wed, 25 Sep 2024 17:03:47 +0100 Subject: [PATCH] CU-8695ydumw: save cdb_file so it gets a storage generated path before checking validity --- webapp/api/api/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/webapp/api/api/models.py b/webapp/api/api/models.py index b0e21a3..dd8b021 100644 --- a/webapp/api/api/models.py +++ b/webapp/api/api/models.py @@ -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