cubicweb/rset.py
changeset 11169 c1eb5a676c80
parent 11168 dfa5f8879e8f
child 11171 b81e543e623a
equal deleted inserted replaced
11168:dfa5f8879e8f 11169:c1eb5a676c80
   487         if req is None:
   487         if req is None:
   488             raise AssertionError('dont call get_entity with no req on the result set')
   488             raise AssertionError('dont call get_entity with no req on the result set')
   489         rowvalues = self.rows[row]
   489         rowvalues = self.rows[row]
   490         eid = rowvalues[col]
   490         eid = rowvalues[col]
   491         assert eid is not None
   491         assert eid is not None
   492         # return cached entity if exists. This also avoids potential recursion
       
   493         # XXX should we consider updating a cached entity with possible
       
   494         #     new attributes found in this resultset ?
       
   495         try:
   492         try:
   496             entity = req.entity_cache(eid)
   493             entity = req.entity_cache(eid)
       
   494             if entity.cw_rset is self:
       
   495                 # return entity as is, avoiding recursion
       
   496                 return entity
   497         except KeyError:
   497         except KeyError:
   498             pass
   498             entity = self._make_entity(row, col)
   499         else:
   499         else:
   500             if entity.cw_rset is None:
   500             if entity.cw_rset is None:
   501                 # entity has no rset set, this means entity has been created by
   501                 # entity has no rset set, this means entity has been created by
   502                 # the querier (req is a repository session) and so has no rset
   502                 # the querier (req is a repository session) and so has no rset
   503                 # info. Add it.
   503                 # info. Add it.
   504                 entity.cw_rset = self
   504                 entity.cw_rset = self
   505                 entity.cw_row = row
   505                 entity.cw_row = row
   506                 entity.cw_col = col
   506                 entity.cw_col = col
   507             return entity
       
   508         entity = self._make_entity(row, col)
       
   509         # try to complete the entity if there are some additional columns
   507         # try to complete the entity if there are some additional columns
   510         if len(rowvalues) > 1:
   508         if len(rowvalues) > 1:
   511             eschema = entity.e_schema
   509             eschema = entity.e_schema
   512             eid_col, attr_cols, rel_cols = self._rset_structure(eschema, col)
   510             eid_col, attr_cols, rel_cols = self._rset_structure(eschema, col)
   513             entity.eid = rowvalues[eid_col]
   511             entity.eid = rowvalues[eid_col]