From ab4a46db7235bf5a1ca4d8d3e30a69960292ab36 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Tue, 7 Jul 2020 14:48:45 +0200 Subject: [PATCH] WIP: new errors in Container.delete, insert, and update --- src/caosdb/common/models.py | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index a509842a..6f134ea8 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) -- GitLab