merge 3.15.x into 3.16.x

authorPierre-Yves David <pierre-yves.david@logilab.fr>
changesetc4aa23af0baa
branchstable
phasepublic
hiddenno
parent revision#dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641), #3a0d91237e2c [devtools] fix a couple issues with xvfb-run
child revision#0d81a474c0fe [editcontroller] a small debugging help (closes #2518980), #064231ce93d5 merge 3.16.x fix in 3.17.x
files modified by this revision
hooks/syncschema.py
selectors.py
server/sources/native.py
server/test/data/schema.py
server/test/unittest_repository.py
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1364470346 -3600
# Thu Mar 28 12:32:26 2013 +0100
# Branch stable
# Node ID c4aa23af0baab02ef8dfa25ec3cec8f9524108d3
# Parent 3a0d91237e2c5c4f925ae31d490efcb8d0266a45
# Parent dbffb6959564baed44c96b322e86da80f1858030
merge 3.15.x into 3.16.x

diff --git a/hooks/syncschema.py b/hooks/syncschema.py
@@ -505,10 +505,12 @@
1                  session.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column),
2                                     {'default': default})
3 
4      def revertprecommit_event(self):
5          # revert changes on in memory schema
6 +        if getattr(self, 'rdefdef', None) is None:
7 +            return
8          self.session.vreg.schema.del_relation_def(
9              self.rdefdef.subject, self.rdefdef.name, self.rdefdef.object)
10          # XXX revert changes on database
11 
12 
diff --git a/server/sources/native.py b/server/sources/native.py
@@ -754,17 +754,21 @@
13                  # need string comparison because of various backends
14                  for arg in ex.args:
15                      mo = re.search('unique_cw_[^ ]+_idx', arg)
16                      if mo is not None:
17                          index_name = mo.group(0)
18 -                        elements = index_name.rstrip('_idx').split('_cw_')[1:]
19 +                        # right-chop '_idx' postfix
20 +                        # (garanteed to be there, see regexp above)
21 +                        elements = index_name[:-4].split('_cw_')[1:]
22                          etype = elements[0]
23                          rtypes = elements[1:]
24                          raise UniqueTogetherError(etype, rtypes)
25                      mo = re.search('columns (.*) are not unique', arg)
26                      if mo is not None: # sqlite in use
27 -                        rtypes = [c.strip().lstrip('cw_') for c in mo.group(1).split(',')]
28 +                        # we left chop the 'cw_' prefix of attribute names
29 +                        rtypes = [c.strip()[3:]
30 +                                  for c in mo.group(1).split(',')]
31                          etype = '???'
32                          raise UniqueTogetherError(etype, rtypes)
33              raise
34          return cursor
35 
diff --git a/server/test/data/schema.py b/server/test/data/schema.py
@@ -50,10 +50,11 @@
36      todo_by = SubjectRelation('Personne', cardinality='?*')
37      documented_by = SubjectRelation('Card')
38 
39 
40  class Societe(EntityType):
41 +    __unique_together__ = [('nom', 'type', 'cp')]
42      __permissions__ = {
43          'read': ('managers', 'users', 'guests'),
44          'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
45          'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
46          'add': ('managers', 'users',)
diff --git a/server/test/unittest_repository.py b/server/test/unittest_repository.py
@@ -49,10 +49,19 @@
47  class RepositoryTC(CubicWebTC):
48      """ singleton providing access to a persistent storage for entities
49      and relation
50      """
51 
52 +    def test_uniquetogether(self):
53 +        self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
54 +        with self.assertRaises(ValidationError) as wraperr:
55 +            self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
56 +        self.assertEqual({'nom': u'violates unique_together constraints (cp, nom, type)',
57 +                          'cp': u'violates unique_together constraints (cp, nom, type)',
58 +                          'type': u'violates unique_together constraints (cp, nom, type)'},
59 +                     wraperr.exception.args[1])
60 +
61      def test_fill_schema(self):
62          origshema = self.repo.schema
63          try:
64              self.repo.schema = CubicWebSchema(self.repo.config.appid)
65              self.repo.config._cubes = None # avoid assertion error