[selectors] fix on_fire_transition for cases where change_state is called (eg no transition specified) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 03 May 2011 11:02:32 +0200
branchstable
changeset 7298 a448e470c150
parent 7297 117dbb11a42e
child 7299 24055a2b63b1
child 7302 c281afe35b8b
[selectors] fix on_fire_transition for cases where change_state is called (eg no transition specified)
selectors.py
test/unittest_rset.py
--- a/selectors.py	Mon May 02 17:24:51 2011 +0200
+++ b/selectors.py	Tue May 03 11:02:32 2011 +0200
@@ -1244,9 +1244,10 @@
     :class:`cubicweb.entities.wfobjs.TrInfo` for more information.
     """
     def match_etype_and_transition(trinfo):
-        # is_instance() first two arguments are 'cls' (unused, so giving None is
-        # fine) and the request/session
-        return (trinfo.transition.name == tr_name
+        # take care trinfo.transition is None when calling change_state
+        return (trinfo.transition and trinfo.transition.name == tr_name
+                # is_instance() first two arguments are 'cls' (unused, so giving
+                # None is fine) and the request/session
                 and is_instance(etype)(None, trinfo._cw, entity=trinfo.for_entity))
 
     return is_instance('TrInfo') & score_entity(match_etype_and_transition)
--- a/test/unittest_rset.py	Mon May 02 17:24:51 2011 +0200
+++ b/test/unittest_rset.py	Tue May 03 11:02:32 2011 +0200
@@ -114,7 +114,6 @@
                        description=[['CWUser', 'String']] * 3)
         rs.req = self.request()
         rs.vreg = self.vreg
-
         self.assertEqual(rs.limit(2).rows, [[12000, 'adim'], [13000, 'syt']])
         rs2 = rs.limit(2, offset=1)
         self.assertEqual(rs2.rows, [[13000, 'syt'], [14000, 'nico']])