fix: yams API only accept str/Definition name now (this is retrocompatible)

authorLaurent Peuch <cortex@worlddomination.be>
changesetb9e72b97a0e3
branchdefault
phasedraft
hiddenno
parent revision#2f3cb7f5a92f chore(flake8): update flake8-ok-files.txt with files that passes flake8 test
child revision<not specified>
files modified by this revision
cubicweb/entities/adapters.py
cubicweb/entity.py
cubicweb/hooks/integrity.py
cubicweb/hooks/syncschema.py
cubicweb/rqlrewrite.py
cubicweb/schema.py
cubicweb/schemas/bootstrap.py
cubicweb/server/migractions.py
cubicweb/server/querier.py
cubicweb/server/schema2sql.py
cubicweb/server/test/unittest_migractions.py
cubicweb/skeleton/test/test_CUBENAME.py.tmpl
cubicweb/web/views/uicfg.py
# HG changeset patch
# User Laurent Peuch <cortex@worlddomination.be>
# Date 1593655624 -7200
# Thu Jul 02 04:07:04 2020 +0200
# Node ID b9e72b97a0e3907132c7a250d1e436b52ff70604
# Parent 2f3cb7f5a92f4c3a70a5abf30227d6228b614804
fix: yams API only accept str/Definition name now (this is retrocompatible)

diff --git a/cubicweb/entities/adapters.py b/cubicweb/entities/adapters.py
@@ -576,11 +576,11 @@
1 
2      def raise_user_exception(self):
3          cstrname = self.exc.cstrname
4          eschema = self.entity.e_schema
5          for rschema, attrschema in eschema.attribute_definitions():
6 -            rdef = rschema.rdef(eschema, attrschema)
7 +            rdef = rschema.rdef(eschema.type, attrschema.type)
8              for constraint in rdef.constraints:
9                  if cstrname == constraint_name_for(constraint, rdef):
10                      break
11              else:
12                  continue
diff --git a/cubicweb/entity.py b/cubicweb/entity.py
@@ -779,11 +779,11 @@
13                  continue
14              attr = rschema.type
15              if attr == 'eid':
16                  continue
17              # password retrieval is blocked at the repository server level
18 -            rdef = rschema.rdef(self.e_schema, attrschema)
19 +            rdef = rschema.rdef(self.e_schema.type, attrschema.type)
20              if not self._cw.user.matching_groups(rdef.get_groups('read')) \
21                     or (attrschema.type == 'Password' and skip_pwd):
22                  self.cw_attr_cache[attr] = None
23                  continue
24              yield attr
@@ -962,20 +962,20 @@
25              if targettypes is None:
26                  targettypes = rschema.objects(self.e_schema)
27              else:
28                  select.add_constant_restriction(mainvar, 'is',
29                                                  targettypes, 'etype')
30 -            gcard = greater_card(rschema, (self.e_schema,), targettypes, 0)
31 +            gcard = greater_card(rschema, (self.e_schema.type,), map(str, targettypes), 0)
32          else:
33              rel = make_relation(mainvar, rtype, (evar,), VariableRef)
34              select.add_restriction(rel)
35              if targettypes is None:
36                  targettypes = rschema.subjects(self.e_schema)
37              else:
38                  select.add_constant_restriction(mainvar, 'is', targettypes,
39                                                  'etype')
40 -            gcard = greater_card(rschema, targettypes, (self.e_schema,), 1)
41 +            gcard = greater_card(rschema, map(str, targettypes), (self.e_schema.type,), 1)
42          etypecls = vreg['etypes'].etype_class(targettypes[0])
43          if len(targettypes) > 1:
44              fetchattrs = vreg['etypes'].fetch_attrs(targettypes)
45              self._fetch_ambiguous_rtypes(select, mainvar, fetchattrs,
46                                           targettypes, vreg.schema)
@@ -1190,14 +1190,14 @@
47          """set cached values for the given relation"""
48          if rset:
49              related = tuple(rset.entities(0))
50              rschema = self._cw.vreg.schema.rschema(rtype)
51              if role == 'subject':
52 -                rcard = rschema.rdef(self.e_schema, related[0].e_schema).cardinality[1]
53 +                rcard = rschema.rdef(self.e_schema.type, related[0].e_schema.type).cardinality[1]
54                  target = 'object'
55              else:
56 -                rcard = rschema.rdef(related[0].e_schema, self.e_schema).cardinality[0]
57 +                rcard = rschema.rdef(related[0].e_schema.type, self.e_schema.type).cardinality[0]
58                  target = 'subject'
59              if rcard in '?1':
60                  for rentity in related:
61                      rentity._cw_related_cache['%s_%s' % (rtype, target)] = (
62                          self.as_rset(), (self,))
diff --git a/cubicweb/hooks/integrity.py b/cubicweb/hooks/integrity.py
@@ -165,11 +165,11 @@
63          eschema = self.entity.e_schema
64          for rschema, targetschemas, role in eschema.relation_definitions():
65              # skip automatically handled relations
66              if rschema.type in DONT_CHECK_RTYPES_ON_ADD:
67                  continue
68 -            rdef = rschema.role_rdef(eschema, targetschemas[0], role)
69 +            rdef = rschema.role_rdef(eschema.type, targetschemas[0].type, role)
70              if rdef.role_cardinality(role) in '1+':
71                  if role == 'subject':
72                      op = _CheckSRelationOp.get_instance(self._cw)
73                  else:
74                      op = _CheckORelationOp.get_instance(self._cw)
diff --git a/cubicweb/hooks/syncschema.py b/cubicweb/hooks/syncschema.py
@@ -895,11 +895,12 @@
75      """actually remove the relation type from the instance's schema"""
76      rtype = None  # make pylint happy
77 
78      def postcommit_event(self):
79          try:
80 -            self.cnx.vreg.schema.del_relation_type(self.rtype)
81 +            relation = self.cnx.vreg.schema.rschema(self.rtype)
82 +            self.cnx.vreg.schema.del_relation_type(relation)
83          except KeyError:
84              # s/o entity type have already been deleted
85              pass
86 
87 
diff --git a/cubicweb/rqlrewrite.py b/cubicweb/rqlrewrite.py
@@ -168,11 +168,11 @@
88      target types returned by the `ttypes_func` function all have single (1 or ?)
89      cardinality.
90      """
91      for etype in etypes:
92          for ttype in ttypes_func(etype):
93 -            if rdef(etype, ttype).cardinality[cardindex] in '+*':
94 +            if rdef(etype, ttype.type).cardinality[cardindex] in '+*':
95                  return True
96      return False
97 
98 
99  def _compatible_relation(relations, stmt, sniprel):
diff --git a/cubicweb/schema.py b/cubicweb/schema.py
@@ -825,11 +825,11 @@
100 
101      def add_subject_relation(self, rschema):
102          """register the relation schema as possible subject relation"""
103          super(CubicWebEntitySchema, self).add_subject_relation(rschema)
104          if rschema.final:
105 -            if self.rdef(rschema).get('fulltextindexed'):
106 +            if self.rdef(rschema.type).get('fulltextindexed'):
107                  self._update_has_text()
108          elif rschema.fulltext_container:
109              self._update_has_text()
110 
111      def add_object_relation(self, rschema):
@@ -853,11 +853,11 @@
112          need_has_text = None
113          for rschema in self.subject_relations():
114              if rschema.final:
115                  if rschema == 'has_text':
116                      has_has_text = True
117 -                elif self.rdef(rschema).get('fulltextindexed'):
118 +                elif self.rdef(rschema.type).get('fulltextindexed'):
119                      may_need_has_text = True
120              elif rschema.fulltext_container:
121                  if rschema.fulltext_container == 'subject':
122                      may_need_has_text = True
123                  else:
@@ -939,11 +939,11 @@
124          return self.type in SCHEMA_TYPES
125 
126      def may_have_permission(self, action, req, eschema=None, role=None):
127          if eschema is not None:
128              for tschema in self.targets(eschema, role):
129 -                rdef = self.role_rdef(eschema, tschema, role)
130 +                rdef = self.role_rdef(eschema.type, tschema.type, role)
131                  if rdef.may_have_permission(action, req):
132                      return True
133          else:
134              for rdef in self.rdefs.values():
135                  if rdef.may_have_permission(action, req):
@@ -1085,10 +1085,11 @@
136              except AttributeError:
137                  pass  # not a serialized schema
138          return rdefs
139 
140      def del_relation_type(self, rtype):
141 +        assert isinstance(rtype, RelationSchema)
142          rschema = self.rschema(rtype)
143          self._eid_index.pop(rschema.eid, None)
144          super(CubicWebSchema, self).del_relation_type(rschema)
145 
146      def del_relation_def(self, subjtype, rtype, objtype):
diff --git a/cubicweb/schemas/bootstrap.py b/cubicweb/schemas/bootstrap.py
@@ -351,7 +351,7 @@
147      wftypes = WORKFLOW_TYPES - set(('TrInfo',))
148      for eschema in schema.entities():
149          if eschema in SCHEMA_TYPES or eschema in wftypes:
150              for rschema in eschema.subject_relations():
151                  if rschema.final and not rschema in META_RTYPES:
152 -                    rdef = eschema.rdef(rschema)
153 +                    rdef = eschema.rdef(rschema.type)
154                      rdef.permissions = PUB_SYSTEM_ATTR_PERMS
diff --git a/cubicweb/server/migractions.py b/cubicweb/server/migractions.py
@@ -41,11 +41,11 @@
155 
156  from logilab.common.decorators import cached, clear_cache
157 
158  from yams.buildobjs import EntityType
159  from yams.constraints import SizeConstraint
160 -from yams.schema import RelationDefinitionSchema
161 +from yams.schema import RelationDefinitionSchema, ERSchema
162 
163  from cubicweb import CW_SOFTWARE_ROOT, ETYPE_NAME_MAP, AuthenticationError, ExecutionError
164  from cubicweb.predicates import is_instance
165  from cubicweb.schema import (META_RTYPES, VIRTUAL_RTYPES,
166                               PURE_VIRTUAL_RTYPES,
@@ -460,11 +460,11 @@
167              for subj, obj in rschema.rdefs:
168                  if (subj, obj) not in reporschema.rdefs:
169                      continue
170                  if rschema in VIRTUAL_RTYPES:
171                      continue
172 -                self._synchronize_rdef_schema(subj, rschema, obj,
173 +                self._synchronize_rdef_schema(subj, rschema.type, obj,
174                                                syncprops=syncprops,
175                                                syncperms=syncperms)
176 
177      def _synchronize_eschema(self, etype, syncrdefs=True,
178                               syncperms=True, syncprops=True):
@@ -507,26 +507,26 @@
179                  if rschema in VIRTUAL_RTYPES:
180                      continue
181                  if role == 'subject':
182                      if rschema not in repoeschema.subject_relations():
183                          continue
184 -                    subjtypes, objtypes = [etype], targettypes
185 +                    subjtypes, objtypes = [etype], map(str, targettypes)
186                  else:  # role == 'object'
187                      if rschema not in repoeschema.object_relations():
188                          continue
189 -                    subjtypes, objtypes = targettypes, [etype]
190 +                    subjtypes, objtypes = map(str, targettypes), [etype]
191                  self._synchronize_rschema(rschema, syncrdefs=False,
192                                            syncprops=syncprops, syncperms=syncperms)
193                  if rschema.rule:  # rdef for computed rtype are infered hence should not be
194                                    # synchronized
195                      continue
196 -                reporschema = self.repo.schema.rschema(rschema)
197 +                reporschema = self.repo.schema.rschema(rschema.type)
198                  for subj in subjtypes:
199                      for obj in objtypes:
200                          if (subj, obj) not in reporschema.rdefs:
201                              continue
202 -                        self._synchronize_rdef_schema(subj, rschema, obj,
203 +                        self._synchronize_rdef_schema(subj, rschema.type, obj,
204                                                        syncprops=syncprops, syncperms=syncperms)
205          if syncprops:  # need to process __unique_together__ after rdefs were processed
206              # mappings from constraint name to columns
207              # filesystem (fs) and repository (repo) wise
208              fs = {}
@@ -570,16 +570,17 @@
209          against its current definition:
210          * order and other properties
211          * constraints
212          * permissions
213          """
214 +        assert isinstance(rtype, str)
215          subjtype, objtype = str(subjtype), str(objtype)
216          rschema = self.fs_schema.rschema(rtype)
217          if rschema.rule:
218              raise ExecutionError('Cannot synchronize a relation definition for a '
219                                   'computed relation (%s)' % rschema)
220 -        reporschema = self.repo.schema.rschema(rschema)
221 +        reporschema = self.repo.schema.rschema(rschema.type)
222          if (subjtype, rschema, objtype) in self._synchronized:
223              return
224          if syncperms and syncprops:
225              self._synchronized.add((subjtype, rschema, objtype))
226              if rschema.symmetric:
@@ -611,11 +612,11 @@
227              # 2. add new constraints
228              cstrtype_map = self.cstrtype_mapping()
229              self.rqlexecall(ss.constraints2rql(cstrtype_map, newconstraints,
230                                                 repordef.eid),
231                              ask_confirm=confirm)
232 -        if syncperms and rschema not in VIRTUAL_RTYPES:
233 +        if syncperms and rschema.type not in VIRTUAL_RTYPES:
234              self._synchronize_permissions(rdef, repordef.eid)
235 
236      # base actions ############################################################
237 
238      def checkpoint(self, ask_confirm=True):
@@ -655,15 +656,15 @@
239          for cube in reversed(newcubes):
240              self.cmd_install_custom_sql_scripts(cube)
241              self.cmd_exec_event_script('precreate', cube)
242          # add new entity and relation types
243          for rschema in newcubes_schema.relations():
244 -            if rschema not in self.repo.schema:
245 +            if rschema.type not in self.repo.schema:
246                  self.cmd_add_relation_type(rschema.type, commit=False)
247                  new.add(rschema.type)
248          toadd = [eschema for eschema in newcubes_schema.entities()
249 -                 if eschema not in self.repo.schema]
250 +                 if eschema.type not in self.repo.schema]
251          for eschema in order_eschemas(toadd):
252              self.cmd_add_entity_type(eschema.type)
253              new.add(eschema.type)
254          # check if attributes has been added to existing entities
255          for rschema in newcubes_schema.relations():
@@ -698,18 +699,18 @@
256          # execute pre-remove files
257          for cube in reversed(removedcubes):
258              self.cmd_exec_event_script('preremove', cube)
259          # remove cubes'entity and relation types
260          for rschema in fsschema.relations():
261 -            if rschema not in removedcubes_schema and rschema in reposchema:
262 +            if rschema.type not in removedcubes_schema and rschema.type in reposchema:
263                  self.cmd_drop_relation_type(rschema.type)
264          toremove = [eschema for eschema in fsschema.entities()
265 -                    if eschema not in removedcubes_schema and eschema in reposchema]
266 +                    if eschema.type not in removedcubes_schema and eschema.type in reposchema]
267          for eschema in reversed(order_eschemas(toremove)):
268              self.cmd_drop_entity_type(eschema.type)
269          for rschema in fsschema.relations():
270 -            if rschema in removedcubes_schema and rschema in reposchema:
271 +            if rschema.type in removedcubes_schema and rschema.type in reposchema:
272                  # check if attributes/relations has been added to entities from
273                  # other cubes
274                  for fromtype, totype in rschema.rdefs:
275                      if (fromtype, totype) not in removedcubes_schema[rschema.type].rdefs and \
276                         (fromtype, totype) in reposchema[rschema.type].rdefs:
@@ -725,12 +726,13 @@
277      # schema migration actions ################################################
278 
279      def cmd_add_attribute(self, etype, attrname, attrtype=None, commit=True):
280          """add a new attribute on the given entity type"""
281          if attrtype is None:
282 -            rschema = self.fs_schema.rschema(attrname)
283 -            attrtype = rschema.objects(etype)[0]
284 +            relation_schema = self.fs_schema.rschema(attrname)
285 +            attrtype = relation_schema.objects(etype)[0].type
286 +
287          self.cmd_add_relation_definition(etype, attrname, attrtype, commit=commit)
288 
289      def cmd_drop_attribute(self, etype, attrname, commit=True):
290          """drop an existing attribute from the given entity type
291 
@@ -750,21 +752,26 @@
292          """rename an existing attribute of the given entity type
293 
294          `oldname` is a string giving the name of the existing attribute
295          `newname` is a string giving the name of the renamed attribute
296          """
297 -        eschema = self.fs_schema.eschema(etype)
298 -        attrtype = eschema.destination(newname)
299 +        entity_schema = self.fs_schema.eschema(etype)
300 +        attribute_type = entity_schema.destination(newname).type
301 +
302          # have to commit this first step anyway to get the definition
303          # actually in the schema
304 -        self.cmd_add_attribute(etype, newname, attrtype, commit=True)
305 +        self.cmd_add_attribute(etype, newname, attribute_type, commit=True)
306 +
307          # skipp NULL values if the attribute is required
308          rql = 'SET X %s VAL WHERE X is %s, X %s VAL' % (newname, etype, oldname)
309 -        card = eschema.rdef(newname).cardinality[0]
310 -        if card == '1':
311 +
312 +        cardinality = entity_schema.rdef(newname).cardinality[0]
313 +        if cardinality == '1':
314              rql += ', NOT X %s NULL' % oldname
315 +
316          self.rqlexec(rql, ask_confirm=self.verbosity >= 2)
317 +
318          # XXX if both attributes fulltext indexed, should skip fti rebuild
319          # XXX if old attribute was fti indexed but not the new one old value
320          # won't be removed from the index (this occurs on other kind of
321          # fulltextindexed change...)
322          self.cmd_drop_attribute(etype, oldname, commit=commit)
@@ -783,21 +790,21 @@
323          confirm = self.verbosity >= 2
324          groupmap = self.group_mapping()
325          cstrtypemap = self.cstrtype_mapping()
326          # register the entity into CWEType
327          execute = self.cnx.execute
328 -        if eschema.final and eschema not in instschema:
329 +        if eschema.final and eschema.type not in instschema:
330              # final types are expected to be in the living schema by default, but they are not if
331              # the type is defined in a cube that is being added
332              edef = EntityType(eschema.type, __permissions__=eschema.permissions)
333              instschema.add_entity_type(edef)
334          ss.execschemarql(execute, eschema, ss.eschema2rql(eschema, groupmap))
335          # add specializes relation if needed
336          specialized = eschema.specializes()
337          if specialized:
338              try:
339 -                specialized.eid = instschema[specialized].eid
340 +                specialized.eid = instschema[specialized.type].eid
341              except KeyError:
342                  raise ExecutionError('trying to add entity type but parent type is '
343                                       'not yet in the database schema')
344              self.rqlexecall(ss.eschemaspecialize2rql(eschema), ask_confirm=confirm)
345          # register entity's attributes
@@ -809,28 +816,28 @@
346                  self.cmd_add_entity_type(attrschema.type, False, False)
347              if rschema.type not in instschema:
348                  # need to add the relation type
349                  self.cmd_add_relation_type(rschema.type, False, commit=False)
350              # register relation definition
351 -            rdef = self._get_rdef(rschema, eschema, eschema.destination(rschema))
352 +            rdef = self._get_rdef(rschema, eschema.type, eschema.destination(rschema).type)
353              ss.execschemarql(execute, rdef, ss.rdef2rql(rdef, cstrtypemap, groupmap),)
354          self.commit()
355          # take care to newly introduced base class
356          # XXX some part of this should probably be under the "if auto" block
357          for spschema in eschema.specialized_by(recursive=False):
358              try:
359 -                instspschema = instschema[spschema]
360 +                instspschema = instschema[spschema.type]
361              except KeyError:
362                  # specialized entity type not in schema, ignore
363                  continue
364              if instspschema.specializes() != eschema:
365                  self.rqlexec('SET D specializes P WHERE D eid %(d)s, P name %(pn)s',
366                               {'d': instspschema.eid, 'pn': eschema.type},
367                               ask_confirm=confirm)
368                  for rschema, tschemas, role in spschema.relation_definitions(True):
369                      for tschema in tschemas:
370 -                        if tschema not in instschema:
371 +                        if tschema.type not in instschema:
372                              continue
373                          if role == 'subject':
374                              subjschema = spschema
375                              objschema = tschema
376                              if rschema.final and rschema in instspschema.subjrels:
@@ -839,13 +846,13 @@
377                                  # simply skip here
378                                  continue
379                          elif role == 'object':
380                              subjschema = tschema
381                              objschema = spschema
382 -                        if (rschema.rdef(subjschema, objschema).infered
383 +                        if (rschema.rdef(subjschema.type, objschema.type).infered
384                              or (instschema.has_relation(rschema) and
385 -                                (subjschema, objschema) in instschema[rschema].rdefs)):
386 +                                (subjschema.type, objschema.type) in instschema[rschema.type].rdefs)):
387                              continue
388                          self.cmd_add_relation_definition(
389                              subjschema.type, rschema.type, objschema.type)
390          if auto:
391              # we have commit here to get relation types actually in the schema
@@ -871,11 +878,11 @@
392                          rtypeadded = True
393                      # register relation definition
394                      # remember this two avoid adding twice non symmetric relation
395                      # such as "Emailthread forked_from Emailthread"
396                      added.append((etype, rschema.type, targettype))
397 -                    rdef = self._get_rdef(rschema, eschema, targetschema)
398 +                    rdef = self._get_rdef(rschema, eschema.type, targetschema.type)
399                      ss.execschemarql(execute, rdef,
400                                       ss.rdef2rql(rdef, cstrtypemap, groupmap))
401              for rschema in eschema.object_relations():
402                  if rschema.type in META_RTYPES:
403                      continue
@@ -894,11 +901,11 @@
404                          self.cmd_add_relation_type(rschema.type, False, commit=False)
405                          rtypeadded = True
406                      elif (targettype, rschema.type, etype) in added:
407                          continue
408                      # register relation definition
409 -                    rdef = self._get_rdef(rschema, targetschema, eschema)
410 +                    rdef = self._get_rdef(rschema, targetschema.type, eschema.type)
411                      ss.execschemarql(execute, rdef,
412                                       ss.rdef2rql(rdef, cstrtypemap, groupmap))
413          if commit:
414              self.commit()
415 
@@ -1042,11 +1049,16 @@
416                      continue
417                  # symmetric relations appears twice
418                  if (subj, obj) in done:
419                      continue
420                  done.add((subj, obj))
421 -                self.cmd_add_relation_definition(subj, rtype, obj)
422 +
423 +                # retrocompatible code, relation_schem.relation_definitions as changed of type
424 +                subj_type = subj.type if isinstance(subj, ERSchema) else subj
425 +                obj_type = obj.type if isinstance(obj, ERSchema) else obj
426 +
427 +                self.cmd_add_relation_definition(subj_type, rtype, obj_type)
428              if rtype in META_RTYPES:
429                  # if the relation is in META_RTYPES, ensure we're adding it for
430                  # all entity types *in the persistent schema*, not only those in
431                  # the fs schema
432                  for etype in self.repo.schema.entities():
@@ -1116,17 +1128,19 @@
433                                       self.group_mapping()))
434          if commit:
435              self.commit()
436 
437      def _get_rdef(self, rschema, subjtype, objtype):
438 +        assert isinstance(subjtype, str), f"{type(subjtype)}"
439 +        assert isinstance(objtype, str), f"{type(objtype)}"
440          return self._set_rdef_eid(rschema.rdefs[(subjtype, objtype)])
441 
442      def _set_rdef_eid(self, rdef):
443          for attr in ('rtype', 'subject', 'object'):
444              schemaobj = getattr(rdef, attr)
445              if getattr(schemaobj, 'eid', None) is None:
446 -                schemaobj.eid = self.repo.schema[schemaobj].eid
447 +                schemaobj.eid = self.repo.schema[schemaobj.type].eid
448                  assert schemaobj.eid is not None, \
449                      '%s has no eid while adding %s' % (schemaobj, rdef)
450          return rdef
451 
452      def cmd_drop_relation_definition(self, subjtype, rtype, objtype, commit=True):
@@ -1168,10 +1182,11 @@
453          """
454          assert syncperms or syncprops, 'nothing to do'
455          if ertype is not None:
456              if isinstance(ertype, RelationDefinitionSchema):
457                  ertype = ertype.as_triple()
458 +                ertype = [ertype[0].type, ertype[1].type, ertype[2].type]
459              if isinstance(ertype, (tuple, list)):
460                  assert len(ertype) == 3, 'not a relation definition'
461                  self._synchronize_rdef_schema(ertype[0], ertype[1], ertype[2],
462                                                syncperms=syncperms,
463                                                syncprops=syncprops)
@@ -1501,11 +1516,11 @@
464            underlying rdbms (eg using ALTER TABLE)
465          * the actual schema won't be updated until next startup
466          """
467          rschema = self.repo.schema.rschema(attr)
468          oldschema = rschema.objects(etype)[0]
469 -        rdef = rschema.rdef(etype, oldschema)
470 +        rdef = rschema.rdef(etype, oldschema.type)
471          sql = ("UPDATE cw_CWAttribute "
472                 "SET cw_to_entity=(SELECT cw_eid FROM cw_CWEType WHERE cw_name='%s')"
473                 "WHERE cw_eid=%s") % (newtype, rdef.eid)
474          self.sqlexec(sql, ask_confirm=False)
475          dbhelper = self.repo.system_source.dbhelper
@@ -1517,17 +1532,17 @@
476          dbhelper.change_col_type(cursor, 'cw_%s' % etype, 'cw_%s' % attr, sqltype, allownull)
477          if commit:
478              self.commit()
479              # manually update live schema
480              eschema = self.repo.schema[etype]
481 -            rschema._subj_schemas[eschema].remove(oldschema)
482 -            rschema._obj_schemas[oldschema].remove(eschema)
483 +            rschema._subj_schemas[eschema.type].remove(oldschema)
484 +            rschema._obj_schemas[oldschema.type].remove(eschema)
485              newschema = self.repo.schema[newtype]
486              rschema._update(eschema, newschema)
487              rdef.object = newschema
488 -            del rschema.rdefs[(eschema, oldschema)]
489 -            rschema.rdefs[(eschema, newschema)] = rdef
490 +            del rschema.rdefs[(eschema.type, oldschema.type)]
491 +            rschema.rdefs[(eschema.type, newschema.type)] = rdef
492 
493      def cmd_add_entity_type_table(self, etype, commit=True):
494          """low level method to create the sql table for an existing entity.
495          This may be useful on accidental desync between the repository schema
496          and a sql database
diff --git a/cubicweb/server/querier.py b/cubicweb/server/querier.py
@@ -87,11 +87,11 @@
497                      continue
498                  rschema = schema.rschema(rel.r_type)
499                  if rschema.final:
500                      eschema = schema.eschema(term_etype(cnx, rel.children[0],
501                                               solution, args))
502 -                    rdef = eschema.rdef(rschema)
503 +                    rdef = eschema.rdef(rschema.type)
504                  else:
505                      rdef = rschema.rdef(term_etype(cnx, rel.children[0],
506                                                     solution, args),
507                                          term_etype(cnx, rel.children[1].children[0],
508                                                     solution, args))
diff --git a/cubicweb/server/schema2sql.py b/cubicweb/server/schema2sql.py
@@ -66,17 +66,17 @@
509      """Yield SQL statements to create a database schema for the given Yams schema.
510 
511      `prefix` may be a string that will be prepended to all table / column names (usually, 'cw_').
512      """
513      for etype in sorted(schema.entities()):
514 -        eschema = schema.eschema(etype)
515 +        eschema = schema.eschema(etype.type)
516          if eschema.final or eschema.type in skip_entities:
517              continue
518          for sql in eschema2sql(dbhelper, eschema, skip_relations, prefix):
519              yield sql
520      for rtype in sorted(schema.relations()):
521 -        rschema = schema.rschema(rtype)
522 +        rschema = schema.rschema(rtype.type)
523          if rschema_has_table(rschema, skip_relations):
524              for sql in rschema2sql(rschema):
525                  yield sql
526 
527 
@@ -152,14 +152,14 @@
528      w(')')
529      yield '\n'.join(output)
530      # create indexes
531      for i in range(len(attrs)):
532          rschema, attrschema = attrs[i]
533 -        if attrschema is None or eschema.rdef(rschema).indexed:
534 +        if attrschema is None or eschema.rdef(rschema.type).indexed:
535              yield dbhelper.sql_create_index(table, prefix + rschema.type)
536          if attrschema and any(isinstance(cstr, UniqueConstraint)
537 -                              for cstr in eschema.rdef(rschema).constraints):
538 +                              for cstr in eschema.rdef(rschema.type).constraints):
539              yield dbhelper.sql_create_index(table, prefix + rschema.type, unique=True)
540      for attrs, index_name in iter_unique_index_names(eschema):
541          columns = ['%s%s' % (prefix, attr) for attr in attrs]
542          sqls = dbhelper.sqls_create_multicol_unique_index(table, columns, index_name)
543          for sql in sqls:
diff --git a/cubicweb/server/test/unittest_migractions.py b/cubicweb/server/test/unittest_migractions.py
@@ -362,11 +362,11 @@
544              mh.cmd_rename_entity_type('Old', 'New')
545              dbh = self.repo.system_source.dbhelper
546              indices = set(dbh.list_indices(cnx.cnxset.cu, 'cw_New'))
547              self.assertNotIn(build_index_name('cw_Old', ['cw_name']), indices)
548              self.assertIn(build_index_name('cw_New', ['cw_name']), indices)
549 -            mh.cmd_rename_attribute('New', 'name', 'new_name')
550 +            mh.cmd_rename_attribute(etype='New', oldname='name', newname='new_name')
551              indices = set(dbh.list_indices(cnx.cnxset.cu, 'cw_New'))
552              # check 'indexed' index
553              self.assertNotIn(build_index_name('cw_New', ['cw_name'], 'idx_'), indices)
554              self.assertIn(build_index_name('cw_New', ['cw_new_name'], 'idx_'), indices)
555              # check 'unique' index
diff --git a/cubicweb/skeleton/test/test_CUBENAME.py.tmpl b/cubicweb/skeleton/test/test_CUBENAME.py.tmpl
@@ -16,15 +16,15 @@
556          to limit test scope
557          '''
558 
559          def to_test_etypes(self):
560              '''only test views for entities of the returned types'''
561 -            return set(('My', 'Cube', 'Entity', 'Types'))
562 +            return set(("My", "Cube", "Entity", "Types"))
563 
564          def list_startup_views(self):
565              '''only test startup views of the returned identifiers'''
566 -            return ('some', 'startup', 'views')
567 +            return ("some", "startup", "views")
568  """
569 
570  from cubicweb.devtools import testlib
571 
572 
diff --git a/cubicweb/web/views/uicfg.py b/cubicweb/web/views/uicfg.py
@@ -72,11 +72,11 @@
573      _allowed_values = frozenset(('attributes', 'relations',
574                                   'sideboxes', 'hidden'))
575 
576      def _init(self, sschema, rschema, oschema, role):
577          if self.get(sschema, rschema, oschema, role) is None:
578 -            rdef = rschema.rdef(sschema, oschema)
579 +            rdef = rschema.rdef(sschema.type, oschema.type)
580              if rschema.final:
581                  if rschema.meta or sschema.is_metadata(rschema) \
582                          or oschema.type in ('Password', 'Bytes'):
583                      section = 'hidden'
584                  else:
@@ -190,11 +190,11 @@
585          result[formtype] = section
586      return result
587 
588 
589  def _card_and_comp(sschema, rschema, oschema, role):
590 -    rdef = rschema.rdef(sschema, oschema)
591 +    rdef = rschema.rdef(sschema.type, oschema.type)
592      if role == 'subject':
593          card = rdef.cardinality[0]
594          composed = not rschema.final and rdef.composite == 'object'
595      else:
596          card = rdef.cardinality[1]
@@ -647,11 +647,11 @@
597          return super(ReleditTags, self).tag_relation(key, tag)
598 
599      def _init(self, sschema, rschema, oschema, role):
600          values = self.get(sschema, rschema, oschema, role)
601          if not rschema.final:
602 -            composite = rschema.rdef(sschema, oschema).composite == role
603 +            composite = rschema.rdef(sschema.type, oschema.type).composite == role
604              if role == 'subject':
605                  oschema = '*'
606              else:
607                  sschema = '*'
608              edittarget = values.get('edit_target')
@@ -683,11 +683,11 @@
609      def _init(self, sschema, rschema, oschema, role):
610          if self.get(sschema, rschema, oschema, role) is None:
611              if rschema in META_RTYPES:
612                  self.tag_relation((sschema, rschema, oschema, role), False)
613                  return
614 -            rdef = rschema.rdef(sschema, oschema)
615 +            rdef = rschema.rdef(sschema.type, oschema.type)
616              if not rdef.role_cardinality(role) in '?1' and rdef.composite == role:
617                  self.tag_relation((sschema, rschema, oschema, role), True)
618 
619      def _tag_etype_attr(self, etype, attr, desttype='*', *args, **kwargs):
620          if isinstance(attr, str):