# HG changeset patch # User Julien Cristau # Date 1392645683 -3600 # Node ID a0cf2993b6d3a8882e9220ceec281cfff3e34075 # Parent e8ec1b23862fafdbd713473def21ae0055bf4c1e [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 diff -r e8ec1b23862f -r a0cf2993b6d3 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