entity.py
changeset 10669 155c29e0ed1c
parent 10662 10942ed172de
child 10689 49a62b8f6d43
equal deleted inserted replaced
10668:4fb62d791073 10669:155c29e0ed1c
   456             rschema = eschema.subjrels[attr] if role == 'subject' else eschema.objrels[attr]
   456             rschema = eschema.subjrels[attr] if role == 'subject' else eschema.objrels[attr]
   457             if not rschema.final and isinstance(value, (tuple, list, set, frozenset)):
   457             if not rschema.final and isinstance(value, (tuple, list, set, frozenset)):
   458                 if len(value) == 0:
   458                 if len(value) == 0:
   459                     continue # avoid crash with empty IN clause
   459                     continue # avoid crash with empty IN clause
   460                 elif len(value) == 1:
   460                 elif len(value) == 1:
   461                     value = iter(value).next()
   461                     value = next(iter(value))
   462                 else:
   462                 else:
   463                     # prepare IN clause
   463                     # prepare IN clause
   464                     pendingrels.append( (attr, role, value) )
   464                     pendingrels.append( (attr, role, value) )
   465                     continue
   465                     continue
   466             if rschema.final: # attribute
   466             if rschema.final: # attribute
   850         if self._cw_completed:
   850         if self._cw_completed:
   851             return
   851             return
   852         if attributes is None:
   852         if attributes is None:
   853             self._cw_completed = True
   853             self._cw_completed = True
   854         varmaker = rqlvar_maker()
   854         varmaker = rqlvar_maker()
   855         V = varmaker.next()
   855         V = next(varmaker)
   856         rql = ['WHERE %s eid %%(x)s' % V]
   856         rql = ['WHERE %s eid %%(x)s' % V]
   857         selected = []
   857         selected = []
   858         for attr in (attributes or self._cw_to_complete_attributes(skip_bytes, skip_pwd)):
   858         for attr in (attributes or self._cw_to_complete_attributes(skip_bytes, skip_pwd)):
   859             # if attribute already in entity, nothing to do
   859             # if attribute already in entity, nothing to do
   860             if attr in self.cw_attr_cache:
   860             if attr in self.cw_attr_cache:
   861                 continue
   861                 continue
   862             # case where attribute must be completed, but is not yet in entity
   862             # case where attribute must be completed, but is not yet in entity
   863             var = varmaker.next()
   863             var = next(varmaker)
   864             rql.append('%s %s %s' % (V, attr, var))
   864             rql.append('%s %s %s' % (V, attr, var))
   865             selected.append((attr, var))
   865             selected.append((attr, var))
   866         # +1 since this doesn't include the main variable
   866         # +1 since this doesn't include the main variable
   867         lastattr = len(selected) + 1
   867         lastattr = len(selected) + 1
   868         # don't fetch extra relation if attributes specified or of the entity is
   868         # don't fetch extra relation if attributes specified or of the entity is
   877                 # * this is a inlined relation
   877                 # * this is a inlined relation
   878                 # * entity (self) is the subject
   878                 # * entity (self) is the subject
   879                 # * user has read perm on the relation and on the target entity
   879                 # * user has read perm on the relation and on the target entity
   880                 assert rschema.inlined
   880                 assert rschema.inlined
   881                 assert role == 'subject'
   881                 assert role == 'subject'
   882                 var = varmaker.next()
   882                 var = next(varmaker)
   883                 # keep outer join anyway, we don't want .complete to crash on
   883                 # keep outer join anyway, we don't want .complete to crash on
   884                 # missing mandatory relation (see #1058267)
   884                 # missing mandatory relation (see #1058267)
   885                 rql.append('%s %s %s?' % (V, rtype, var))
   885                 rql.append('%s %s %s?' % (V, rtype, var))
   886                 selected.append(((rtype, role), var))
   886                 selected.append(((rtype, role), var))
   887         if selected:
   887         if selected: