diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index a509842a41af3868b59ee76e55ccd2981f533bca..6f134ea868f5d8bc5514207b63f6107fbf38c405 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -2637,8 +2637,10 @@ class Container(list): if len(self) == 0: if raise_exception_on_error: - raise TransactionError( - self, "There are no entities to be deleted. This container is empty.") + ce = ContainerError( + "There are no entities to be deleted. This container is empty.", + self) + raise TransactionError(ce) return self self.clear_server_messages() @@ -2662,15 +2664,17 @@ class Container(list): description="This entity has no identifier. It cannot be deleted.")) if raise_exception_on_error: - raise EntityError( + ee = EntityError( "This entity has no identifier. It cannot be deleted.", entity) + raise TransactionError(ee) else: entity.is_valid = lambda: False if len(id_str) == 0: if raise_exception_on_error: - raise TransactionError( - self, "There are no entities to be deleted.") + ce = ContainerError( + "There are no entities to be deleted.", self) + raise TransactionError(ce) return self entity_url_segments = [_ENTITY_URI_SEGMENT, "&".join(id_str)] @@ -2822,9 +2826,10 @@ class Container(list): """Update these entites.""" if len(self) < 1: - raise TransactionError( - container=self, - msg="There are no entities to be updated. This container is empty.") + ce = ContainerError( + "There are no entities to be updated. This container is empty.", + self) + raise TransactionError(ce) self.clear_server_messages() insert_xml = etree.Element("Update") @@ -2841,8 +2846,10 @@ class Container(list): for entity in self: if (entity.id is None or entity.id < 0): - raise TransactionError( - self, "You tried to update an entity without a valid id.") + ee = EntityError( + "You tried to update an entity without a valid id.", + entity) + raise TransactionError(ee) self._linearize() @@ -3012,9 +3019,10 @@ class Container(list): insert_xml.append(entity_xml) if len(self) > 0 and len(insert_xml) < 1: - raise TransactionError( - container=self, - msg="There are no entities to be inserted. This container contains existent entities only.") + ce = ContainerError( + "There are no entities to be inserted. This container contains existent entities only.", + self) + raise TransactionError(ce) _log_request("POST: " + _ENTITY_URI_SEGMENT + ('' if flags is None else "?" + str(flags)), insert_xml) @@ -3705,10 +3713,10 @@ def _evaluate_and_add_error(parent_error, ent): new_exc = EntityDoesNotExistError(entity=ent, error=err) elif int(err.code) == 110: # ent has no data type - new_exc=EntityHasNoDatatypeError(entity = ent, - error = err) + new_exc = EntityHasNoDatatypeError(entity=ent, + error=err) elif int(err.code) == 403: # no permission - new_exc=AuthorizationException(entity = ent, + new_exc = AuthorizationException(entity=ent, error=err) elif int(err.code) == 152: # name wasn't unique new_exc = UniqueNamesError(entity=ent, error=err)