[PATCH 3 of 6 seda] [schema] Fix definition of the container relation

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Mar 28 10:58:15 CEST 2017


Le 27/03/2017 à 10:31, Philippe Pepiot a écrit :
> On 03/24/2017 10:48 AM, Sylvain Thenault wrote:
>> # HG changeset patch
>> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
>> # Date 1490200634 -3600
>> #      Wed Mar 22 17:37:14 2017 +0100
>> # Node ID a5a36f8af01cf746882d2ff66b032f89ebe55c65
>> # Parent  97ae1cc7a9e7e129f73fe0a3cb6ec7044b9706fe
>> [schema] Fix definition of the container relation
>>
>> Cardinality and permissions defined on the relation type wasn't
>> considered as
>> expected because the relation is added dynamically in
>> post_build_callback. We
>> have to set them explicitly there.
>>
>> This added to a bug in the cloning code led to entities with several
>> containers.
>> To fix this, migration script pick the container with the greatest
>> eid since it
>> should be the one which is not unexpectedly copied. Anyway, even if
>> that's wrong
>> that's no big deal because there are only demo instances for now
>> which don't
>> really care of data loss.
>>
>> diff --git a/cubicweb_seda/migration/0.9.1_Any.py
>> b/cubicweb_seda/migration/0.9.1_Any.py
>> new file mode 100644
>> --- /dev/null
>> +++ b/cubicweb_seda/migration/0.9.1_Any.py
>> @@ -0,0 +1,9 @@
>> +for e in rql('Any X groupby X WHERE X container C HAVING COUNT(C) >
>> 1').entities():
>> +    container = min(c.eid for c in e.container)
>> +    e.cw_set(container=None)
>> +    e.cw_set(container=container)
>> +    commit()
>
> Commit message say 'pick the container with the greatest eid' but you
> actually pick the lowest.

good catch :$
>
>> +
>> +sync_schema_props_perms('container')
>> +
>> +
>> diff --git a/cubicweb_seda/schema/__init__.py
>> b/cubicweb_seda/schema/__init__.py
>> --- a/cubicweb_seda/schema/__init__.py
>> +++ b/cubicweb_seda/schema/__init__.py
>> @@ -84,12 +84,10 @@ class seda_keyword_reference_to_scheme(R
>>      cardinality = '?*'
>>      inlined = True
>>
>>
>>  class container(RelationType):
>> -    __permissions__ = {'add': (), 'delete': (), 'read': ()}
>> -    cardinality = '1*'
>>      inlined = False
>>
>>
>>  class _clone_of(RelationDefinition):
>>      __permissions__ = {'read': ('managers', 'users', 'guests'),
>> @@ -169,11 +167,16 @@ def post_build_callback(schema):
>>
>>      container_etypes = ('SEDAArchiveTransfer', 'SEDAArchiveUnit')
>>      for etype, parent_rdefs in seda_profile_container_def(schema):
>>          # add relation to the container from every entity type
>> within the compound graph
>>          for container_etype in container_etypes:
>> -            container_rdef = RelationDefinition(etype, 'container',
>> container_etype)
>> +            container_rdef = RelationDefinition(
>> +                etype, 'container', container_etype,
>> +                cardinality='?*' if etype == 'SEDAArchiveUnit' else
>> '1*',
>
> Can you explain the difference of cardinality between
> SEDAArchiveTransfer and SEDAArchiveUnit in the commit message ? I
> don't understand if the cardinality is changed by this patch or not
> for each container etypes.

Added an inline comment and an explanation in the  commit message

Sent a V2

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list