From 862d53750bedafca29df5e728e3f2d6d3af810ff Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Wed, 8 Jul 2020 17:05:32 +0200
Subject: [PATCH] ENH: Replace ContainerError by TransactionError again

---
 src/caosdb/common/models.py |  2 +-
 src/caosdb/exceptions.py    | 33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py
index 8de67513..4792f46c 100644
--- a/src/caosdb/common/models.py
+++ b/src/caosdb/common/models.py
@@ -49,7 +49,7 @@ from caosdb.connection.encode import MultipartParam, multipart_encode
 from caosdb.exceptions import (AmbiguityException,
                                AuthorizationException,
                                CaosDBException, ConnectionException,
-                               ConsistencyError,
+                               ConsistencyError, ContainerError,
                                EntityDoesNotExistError, EntityError,
                                EntityHasNoDatatypeError,
                                TransactionError, UniqueNamesError,
diff --git a/src/caosdb/exceptions.py b/src/caosdb/exceptions.py
index 5f3b0038..3beec3cc 100644
--- a/src/caosdb/exceptions.py
+++ b/src/caosdb/exceptions.py
@@ -148,12 +148,14 @@ class TransactionError(CaosDBException):
     """
 
     def __init__(self, error=None,
-                 msg="An error occured during the transaction."):
+                 msg="An error occured during the transaction.",
+                 container=None):
         self.errors = []
         self.all_errors = set()
         self.entities = []
         self.all_entities = set()
         self.msg = msg
+        self.container = container
         if error is not None:
             self.add_error(error)
 
@@ -242,6 +244,24 @@ class TransactionError(CaosDBException):
 
         return self.all_entities
 
+    def get_container(self):
+        """Return the Container object that contained the problematic
+        entities.  
+
+        Returns
+        -------
+        Container
+            Either the container that caused this error (which
+            contains at least one faulty entity) or, if none was given
+            during construction, a new container containing
+            self.entities instead.
+
+        """
+        if self.container is not None:
+            return self.container
+        from caosdb import Container
+        return Container().extend(self.entities)
+
     def get_error(self):
         """If this Transaction error was caused by exactly one EntityError,
         return this error. Raise an AmbiguityException otherwise.
@@ -382,14 +402,3 @@ class AuthorizationException(EntityError):
     Maybe you need more privileges or a user account at all.
 
     """
-
-
-class ContainerError(EntityError):
-    """The container contains one or more entities that caused errors."""
-    def _repr_head(self, indent):
-        if hasattr(self, "entity") and self.entity is not None:
-            return (str(type(self.entity).__name__).upper() +
-                    " CAUSED " +
-                    TransactionError._repr_head(self, indent))
-        else:
-            return TransactionError._repr_head(self, indent)
-- 
GitLab