From 959b4a8ef5e3dcda4655fc7419fb9e83594fa124 Mon Sep 17 00:00:00 2001 From: fspreck <f.spreckelsen@indiscale.com> Date: Fri, 15 Jan 2021 17:13:53 +0100 Subject: [PATCH] API: Remove AmbiguityError altogether It has been replaced by more meaningful error types in all cases. --- CHANGELOG.md | 1 + src/caosdb/common/models.py | 15 +++++++++++---- src/caosdb/exceptions.py | 8 -------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92324b78..fc71f20d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Dynamic exception type `EntityMultiError`. * `get_something` functions from all error object in `exceptions.py` +* `AmbiguityException` ### Fixed ### diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 7760166f..467e0e71 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -48,7 +48,7 @@ from caosdb.common.utils import uuid, xml2str from caosdb.configuration import get_config from caosdb.connection.connection import get_connection from caosdb.connection.encode import MultipartParam, multipart_encode -from caosdb.exceptions import (AmbiguityError, +from caosdb.exceptions import (AmbiguousEntityError, AuthorizationError, CaosDBException, CaosDBConnectionError, ConsistencyError, @@ -995,11 +995,18 @@ class Entity(object): if self.id is None: c = Container().retrieve(query=self.name, sync=False) - if len(c == 1): + if len(c) == 1: e = c[0] + elif len(c) == 0: + raise EntityDoesNotExistError( + "The entity to be updated does not exist on the server.", + entity=self + ) else: - raise AmbiguityError( - "Could not determine the desired Entity which is to be updated by its name.") + raise AmbiguousEntityError( + "Could not determine the desired Entity which is to be updated by its name.", + entity=self + ) else: e = Container().retrieve(query=self.id, sync=False)[0] e.acl = ACL(self.acl.to_xml()) diff --git a/src/caosdb/exceptions.py b/src/caosdb/exceptions.py index 9217febf..01c3437b 100644 --- a/src/caosdb/exceptions.py +++ b/src/caosdb/exceptions.py @@ -103,14 +103,6 @@ class URITooLongError(HTTPClientError): HTTPClientError.__init__(self, msg=msg, status=414, body=None) -class AmbiguityError(CaosDBException): - """A retrieval of an entity that was supposed to be uniquely identifiable - returned two or more entities.""" - - def __init__(self, msg=None): - CaosDBException.__init__(self, msg) - - class LoginFailedError(CaosDBException): """Login failed. -- GitLab