[source,native] Generalize the IntegrityError constraint parsing regex 3.24
authorFlorent Cayré <florent.cayre@gmail.com>
Fri, 20 Jan 2017 03:48:11 +0100
branch3.24
changeset 11926 2deb9f6cbb7b
parent 11925 b75fc687c730
child 11927 35fd54c0065d
[source,native] Generalize the IntegrityError constraint parsing regex This allows catching constraint-related errors that have been translated by psycopg2, replacing surrounding english quotes by french quotes + space for instance. Closes #17047951.
cubicweb/server/sources/native.py
--- a/cubicweb/server/sources/native.py	Wed Jan 18 16:50:48 2017 +0100
+++ b/cubicweb/server/sources/native.py	Fri Jan 20 03:48:11 2017 +0100
@@ -716,10 +716,10 @@
                         rtypes = [c.split('.', 1)[1].strip()[3:] for c in columns]
                         raise UniqueTogetherError(cnx, rtypes=rtypes)
 
-                    mo = re.search('"cstr[a-f0-9]{32}"', arg)
+                    mo = re.search(r'\bcstr[a-f0-9]{32}\b', arg)
                     if mo is not None:
                         # postgresql
-                        raise ViolatedConstraint(cnx, cstrname=mo.group(0)[1:-1])
+                        raise ViolatedConstraint(cnx, cstrname=mo.group(0))
                     if arg.startswith('CHECK constraint failed:'):
                         # sqlite3 (new)
                         raise ViolatedConstraint(cnx, cstrname=arg.split(':', 1)[1].strip())