# HG changeset patch # User julien tayon # Date 1560238812 -7200 # Node ID de1c0721656e72bfc4fdcf3c1a3ab40895801d2e # Parent 619210ba8b5e5a72f1a282aa28fb4523bda21510 Fix sorting key for rdefs in schema viewer With changeset 234ca3cbbb46, clicking in the schema of an entity with cubicweb in py3 on "vue en boite" will probably result in an infinite spinner (which implies cw > 3.26) What happened ? This "vue en boite" used to work at least until... hg diff -c a8c1ea390400 cubicweb/schema.py @@ -993,10 +992,6 @@ class CubicWebRelationSchema(PermissionM return False return True - @deprecated('use .rdef(subjtype, objtype).role_cardinality(role)') - def cardinality(self, subjtype, objtype, target): - return self.rdef(subjtype, objtype).role_cardinality(target) - class CubicWebSchema(Schema): """set of entities and relations schema defining the possible data sets But, wait ... If I open a shell on an instance of cw 3.24 something seems off >>> list(schema['CWUniqueTogetherConstraint'].relation_definitions())[0][0].cardinality # > We have been sorting on a method the whole time ? Is it possible what were the effects ? 1) We cannot sort function can't we ? >>> def adder(i): return lambda x: x+i >>> sorted(map(adder,range(10))) [>, >, ... Yes we can. 2) what does it means. >>> { adder(1) : 1 } Out[19]: {>: 1} In fact the function object as a __hash__ method (which is practical for making memoizers (cache)), and return truly random results (pseudo random). My take on this patch is relations have NEVER been sorted by cardinality. No one never ever noticed. Hence, I propose to not fix a bug that never was reported. diff -r 619210ba8b5e -r de1c0721656e cubicweb/web/schemaviewer.py --- a/cubicweb/web/schemaviewer.py Tue Jun 04 09:35:47 2019 +0200 +++ b/cubicweb/web/schemaviewer.py Tue Jun 11 09:40:12 2019 +0200 @@ -140,7 +140,7 @@ first = True rel_defs = sorted(eschema.relation_definitions(), - key=lambda el: (el[0].type, el[0].cardinality)) + key=lambda el: el[0].type) for rschema, targetschemas, role in rel_defs: if rschema.type in skiptypes: