# HG changeset patch # User Aurelien Campeas # Date 1364470299 -3600 # Node ID dbffb6959564baed44c96b322e86da80f1858030 # Parent d8b0984c923c45e9be2ef499d4d1f7d31dfd2a85 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641) Fixed an .rstrip(...) for the general case (untested). Fixed an .lstrip(...) for the sqlite path (tested). diff -r d8b0984c923c -r dbffb6959564 server/sources/native.py --- a/server/sources/native.py Thu Mar 28 11:45:17 2013 +0100 +++ b/server/sources/native.py Thu Mar 28 12:31:39 2013 +0100 @@ -758,13 +758,17 @@ 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:] + # right-chop '_idx' postfix + # (garanteed to be there, see regexp above) + elements = index_name[:-4].split('_cw_')[1:] etype = elements[0] rtypes = elements[1:] raise UniqueTogetherError(etype, rtypes) mo = re.search('columns (.*) are not unique', arg) if mo is not None: # sqlite in use - rtypes = [c.strip().lstrip('cw_') for c in mo.group(1).split(',')] + # we left chop the 'cw_' prefix of attribute names + rtypes = [c.strip()[3:] + for c in mo.group(1).split(',')] etype = '???' raise UniqueTogetherError(etype, rtypes) raise diff -r d8b0984c923c -r dbffb6959564 server/test/data/schema.py --- a/server/test/data/schema.py Thu Mar 28 11:45:17 2013 +0100 +++ b/server/test/data/schema.py Thu Mar 28 12:31:39 2013 +0100 @@ -52,6 +52,7 @@ class Societe(EntityType): + __unique_together__ = [('nom', 'type', 'cp')] __permissions__ = { 'read': ('managers', 'users', 'guests'), 'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')), diff -r d8b0984c923c -r dbffb6959564 server/test/unittest_repository.py --- a/server/test/unittest_repository.py Thu Mar 28 11:45:17 2013 +0100 +++ b/server/test/unittest_repository.py Thu Mar 28 12:31:39 2013 +0100 @@ -53,6 +53,15 @@ and relation """ + def test_uniquetogether(self): + self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"') + with self.assertRaises(ValidationError) as wraperr: + self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"') + self.assertEqual({'nom': u'violates unique_together constraints (cp, nom, type)', + 'cp': u'violates unique_together constraints (cp, nom, type)', + 'type': u'violates unique_together constraints (cp, nom, type)'}, + wraperr.exception.args[1]) + def test_fill_schema(self): origshema = self.repo.schema try: