[server] Handle unique constraint violations under recent sqlite
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 17 Feb 2014 15:01:23 +0100
changeset 9546 a0cf2993b6d3
parent 9545 e8ec1b23862f
child 9547 43aace16a953
[server] Handle unique constraint violations under recent sqlite The error message changed from "columns foo, bar, baz are not unique" to "UNIQUE constraint failed: table.foo, table.bar, table.baz". Closes #3564510
server/sources/native.py
--- a/server/sources/native.py	Tue Mar 04 12:02:11 2014 +0100
+++ b/server/sources/native.py	Mon Feb 17 15:01:23 2014 +0100
@@ -660,13 +660,20 @@
                     mo = re.search("unique_[a-z0-9]{32}", arg)
                     if mo is not None:
                         raise UniqueTogetherError(session, cstrname=mo.group(0))
-                    # sqlite
+                    # old sqlite
                     mo = re.search('columns (.*) are not unique', arg)
                     if mo is not None: # sqlite in use
                         # we left chop the 'cw_' prefix of attribute names
                         rtypes = [c.strip()[3:]
                                   for c in mo.group(1).split(',')]
                         raise UniqueTogetherError(session, rtypes=rtypes)
+                    # sqlite after http://www.sqlite.org/cgi/src/info/c80e229dd9c1230a
+                    if arg.startswith('UNIQUE constraint failed:'):
+                        # message looks like: "UNIQUE constraint failed: foo.cw_bar, foo.cw_baz"
+                        # so drop the prefix, split on comma, drop the tablenames, and drop "cw_"
+                        columns = arg.split(':', 1)[1].split(',')
+                        rtypes = [c.split('.', 1)[1].strip()[3:] for c in columns]
+                        raise UniqueTogetherError(session, rtypes=rtypes)
             raise
         return cursor