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).

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changesetdbffb6959564
brancholdstable
phasepublic
hiddenno
parent revision#d8b0984c923c [migration] fix bug in `CWAttributeAddOp.revertprecommit_event`
child revision#ec6b0763ef43 [server] add a db-namespace option in source definition (closes #1631339), #5d08086c3e6d [cmd] fix exlog documentation (closes #2715913), #8d14c264152a [querier] fix eid relations handling in SET queries (closes #2797052), #f3696850f362 [server] add a db-namespace option in source definition (closes #1631339), #c4aa23af0baa merge 3.15.x into 3.16.x
files modified by this revision
server/sources/native.py
server/test/data/schema.py
server/test/unittest_repository.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1364470299 -3600
# Thu Mar 28 12:31:39 2013 +0100
# Branch oldstable
# 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 --git a/server/sources/native.py b/server/sources/native.py
@@ -756,17 +756,21 @@
1                  # need string comparison because of various backends
2                  for arg in ex.args:
3                      mo = re.search('unique_cw_[^ ]+_idx', arg)
4                      if mo is not None:
5                          index_name = mo.group(0)
6 -                        elements = index_name.rstrip('_idx').split('_cw_')[1:]
7 +                        # right-chop '_idx' postfix
8 +                        # (garanteed to be there, see regexp above)
9 +                        elements = index_name[:-4].split('_cw_')[1:]
10                          etype = elements[0]
11                          rtypes = elements[1:]
12                          raise UniqueTogetherError(etype, rtypes)
13                      mo = re.search('columns (.*) are not unique', arg)
14                      if mo is not None: # sqlite in use
15 -                        rtypes = [c.strip().lstrip('cw_') for c in mo.group(1).split(',')]
16 +                        # we left chop the 'cw_' prefix of attribute names
17 +                        rtypes = [c.strip()[3:]
18 +                                  for c in mo.group(1).split(',')]
19                          etype = '???'
20                          raise UniqueTogetherError(etype, rtypes)
21              raise
22          return cursor
23 
diff --git a/server/test/data/schema.py b/server/test/data/schema.py
@@ -50,10 +50,11 @@
24      todo_by = SubjectRelation('Personne', cardinality='?*')
25      documented_by = SubjectRelation('Card')
26 
27 
28  class Societe(EntityType):
29 +    __unique_together__ = [('nom', 'type', 'cp')]
30      __permissions__ = {
31          'read': ('managers', 'users', 'guests'),
32          'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
33          'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
34          'add': ('managers', 'users',)
diff --git a/server/test/unittest_repository.py b/server/test/unittest_repository.py
@@ -51,10 +51,19 @@
35  class RepositoryTC(CubicWebTC):
36      """ singleton providing access to a persistent storage for entities
37      and relation
38      """
39 
40 +    def test_uniquetogether(self):
41 +        self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
42 +        with self.assertRaises(ValidationError) as wraperr:
43 +            self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
44 +        self.assertEqual({'nom': u'violates unique_together constraints (cp, nom, type)',
45 +                          'cp': u'violates unique_together constraints (cp, nom, type)',
46 +                          'type': u'violates unique_together constraints (cp, nom, type)'},
47 +                     wraperr.exception.args[1])
48 +
49      def test_fill_schema(self):
50          origshema = self.repo.schema
51          try:
52              self.repo.schema = CubicWebSchema(self.repo.config.appid)
53              self.repo.config._cubes = None # avoid assertion error