# HG changeset patch # User Sylvain Thénault # Date 1319113072 -7200 # Node ID d43569aaf5d6e960e08663e8b5d77c7900da8eb6 # Parent 63bead9219664bdda3a5592f41f0b5a772fb547d [rset] don't only consider a sample select node / solution to compute rset description. Closes #2036499 those particular ones may miss information that we may found in another select or solution diff -r 63bead921966 -r d43569aaf5d6 server/session.py --- a/server/session.py Tue Oct 18 15:52:12 2011 +0200 +++ b/server/session.py Thu Oct 20 14:17:52 2011 +0200 @@ -61,6 +61,18 @@ description.append(term.get_type(solution, args)) return description +def selection_idx_type(i, rqlst, args): + """try to return type of term at index `i` of the rqlst's selection""" + for select in rqlst.children: + term = select.selection[i] + for solution in select.solutions: + try: + ttype = term.get_type(solution, args) + if ttype is not None: + return ttype + except CoercionError: + return None + @objectify_selector def is_user_session(cls, req, **kwargs): """repository side only selector returning 1 if the session is a regular @@ -1156,20 +1168,13 @@ unstables = rqlst.get_variable_indices() basedescr = [] todetermine = [] - sampleselect = rqlst.children[0] - samplesols = sampleselect.solutions[0] - for i, term in enumerate(sampleselect.selection): - try: - ttype = term.get_type(samplesols, args) - except CoercionError: + for i in xrange(len(rqlst.children[0].selection)): + ttype = selection_idx_type(i, rqlst, args) + if ttype is None or ttype == 'Any': ttype = None isfinal = True else: - if ttype is None or ttype == 'Any': - ttype = None - isfinal = True - else: - isfinal = ttype in BASE_TYPES + isfinal = ttype in BASE_TYPES if ttype is None or i in unstables: basedescr.append(None) todetermine.append( (i, isfinal) ) diff -r 63bead921966 -r d43569aaf5d6 server/test/unittest_session.py --- a/server/test/unittest_session.py Tue Oct 18 15:52:12 2011 +0200 +++ b/server/test/unittest_session.py Thu Oct 20 14:17:52 2011 +0200 @@ -88,7 +88,7 @@ self.assertEqual(session.disabled_hook_categories, set()) self.assertEqual(session.enabled_hook_categories, set()) - def test_build_descr(self): + def test_build_descr1(self): rset = self.execute('(Any U,L WHERE U login L) UNION (Any G,N WHERE G name N, G is CWGroup)') orig_length = len(rset) rset.rows[0][0] = 9999999 @@ -97,6 +97,18 @@ self.assertEqual(len(rset.rows), orig_length - 1) self.failIf(rset.rows[0][0] == 9999999) + def test_build_descr2(self): + rset = self.execute('Any X,Y WITH X,Y BEING ((Any G,NULL WHERE G is CWGroup) UNION (Any U,G WHERE U in_group G))') + for x, y in rset.description: + if y is not None: + self.assertEqual(y, 'CWGroup') + + def test_build_descr3(self): + rset = self.execute('(Any G,NULL WHERE G is CWGroup) UNION (Any U,G WHERE U in_group G)') + for x, y in rset.description: + if y is not None: + self.assertEqual(y, 'CWGroup') + if __name__ == '__main__': unittest_main()