From cbbc561e9971cb161f94be8982e51ab9cebc6590 Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Tue, 22 Sep 2020 11:10:02 +0200
Subject: [PATCH] API: Use BadQueryErrors in unique queries

---
 src/caosdb/common/models.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py
index 7473c041..be0497f2 100644
--- a/src/caosdb/common/models.py
+++ b/src/caosdb/common/models.py
@@ -51,10 +51,11 @@ from caosdb.connection.encode import MultipartParam, multipart_encode
 from caosdb.exceptions import (AmbiguityException,
                                AuthorizationException,
                                CaosDBException, ConnectionException,
-                               ConsistencyError,
+                               ConsistencyError, EmptyUniqueQueryError,
                                EntityDoesNotExistError, EntityError,
                                EntityHasNoDatatypeError,
-                               TransactionError, UniqueNamesError,
+                               TransactionError, QueryNotUniqueError,
+                               UniqueNamesError,
                                UnqualifiedParentsError,
                                UnqualifiedPropertiesError,
                                URITooLongException)
@@ -1038,7 +1039,7 @@ class Entity(object):
 
                 return c[0]
             else:
-                raise AmbiguityException("This retrieval was not unique!!!")
+                raise QueryNotUniqueError("This retrieval was not unique!!!")
         else:
             return Container().append(self).retrieve(
                 unique=unique, raise_exception_on_error=raise_exception_on_error, flags=flags)
@@ -3675,12 +3676,11 @@ class Query():
 
         if unique:
             if len(cresp) > 1 and raise_exception_on_error:
-                raise AmbiguityException(
+                raise QueryNotUniqueError(
                     "Query '{}' wasn't unique.".format(self.q))
             elif len(cresp) == 0 and raise_exception_on_error:
-                ee = EntityDoesNotExistError(
+                raise EmptyUniqueQueryError(
                     "Query '{}' found no results.".format(self.q))
-                raise TransactionError(ee)
             elif len(cresp) == 1:
                 r = cresp[0]
                 r.messages.extend(cresp.messages)
-- 
GitLab