# HG changeset patch # User Alexandre Richardson # Date 1452616588 -3600 # Node ID dfa5f8879e8f35984ebcbaeb49400aa0eab9f48a # Parent e7514e949ad8f82022fac11cd0b18c61ccac9e98 [rset] refactoring of _build_entity method define a method for entity instantiation and storage in cache (related to #9942503) diff -r e7514e949ad8 -r dfa5f8879e8f cubicweb/rset.py --- a/cubicweb/rset.py Thu Feb 25 09:28:21 2016 +0100 +++ b/cubicweb/rset.py Tue Jan 12 17:36:28 2016 +0100 @@ -459,6 +459,17 @@ else: raise MultipleResultsError("Multiple rows were found for one()") + def _make_entity(self, row, col): + """Instantiate an entity, and store it in the entity cache""" + # build entity instance + etype = self.description[row][col] + entity = self.req.vreg['etypes'].etype_class(etype)(self.req, rset=self, + row=row, col=col) + entity.eid = self.rows[row][col] + # cache entity + self.req.set_entity_cache(entity) + return entity + def _build_entity(self, row, col): """internal method to get a single entity, returns a partially initialized Entity instance. @@ -488,19 +499,13 @@ else: if entity.cw_rset is None: # entity has no rset set, this means entity has been created by - # the querier (req is a repository session) and so jas no rset + # the querier (req is a repository session) and so has no rset # info. Add it. entity.cw_rset = self entity.cw_row = row entity.cw_col = col return entity - # build entity instance - etype = self.description[row][col] - entity = self.req.vreg['etypes'].etype_class(etype)(req, rset=self, - row=row, col=col) - entity.eid = eid - # cache entity - req.set_entity_cache(entity) + entity = self._make_entity(row, col) # try to complete the entity if there are some additional columns if len(rowvalues) > 1: eschema = entity.e_schema