server/sources/native.py
branchstable
changeset 6211 e9d125fd1465
parent 6201 cf445fcaf8fe
child 6225 a176e68b7d0d
child 6247 f7cb092d2296
--- a/server/sources/native.py	Fri Sep 10 17:58:38 2010 +0200
+++ b/server/sources/native.py	Fri Sep 10 18:30:38 2010 +0200
@@ -34,6 +34,7 @@
 from base64 import b64decode, b64encode
 from contextlib import contextmanager
 from os.path import abspath
+import re
 
 from logilab.common.compat import any
 from logilab.common.cache import Cache
@@ -44,7 +45,7 @@
 
 from yams import schema2sql as y2sql
 
-from cubicweb import UnknownEid, AuthenticationError, ValidationError, Binary
+from cubicweb import UnknownEid, AuthenticationError, ValidationError, Binary, UniqueTogetherError
 from cubicweb import transaction as tx, server, neg_role
 from cubicweb.schema import VIRTUAL_RTYPES
 from cubicweb.cwconfig import CubicWebNoAppConfiguration
@@ -666,6 +667,16 @@
                         self.critical('transaction has been rollbacked')
                 except:
                     pass
+            if ex.__class__.__name__ == 'IntegrityError':
+                # need string comparison because of various backends
+                for arg in ex.args:
+                    mo = re.search('unique_cw_[^ ]+_idx', arg)
+                    if mo is not None:
+                        index_name = mo.group(0)
+                        elements = index_name.rstrip('_idx').split('_cw_')[1:]
+                        etype = elements[0]
+                        rtypes = elements[1:]                        
+                        raise UniqueTogetherError(etype, rtypes)
             raise
         return cursor