Operation.session is deprecated use Operation.cnx
authorSamuel Trégouët <samuel.tregouet@logilab.fr>
Tue, 26 Sep 2017 11:19:32 +0200
changeset 188 6fb2d871eb7f
parent 187 2e7dc26727f6
child 189 0021cffb5f43
Operation.session is deprecated use Operation.cnx
cubicweb_keyword/hooks.py
--- a/cubicweb_keyword/hooks.py	Wed Sep 27 09:08:03 2017 +0200
+++ b/cubicweb_keyword/hooks.py	Tue Sep 26 11:19:32 2017 +0200
@@ -79,28 +79,28 @@
     already setting the relation
     """
     def precommit_event(self):
-        session = self.session
+        cnx = self.cnx
         # test for indirect cycles
         self.check_cycle()
-        subkw = session.entity_from_eid(self.eidfrom)
+        subkw = cnx.entity_from_eid(self.eidfrom)
         if subkw.included_in:
-            kw = session.entity_from_eid(self.eidto)
+            kw = cnx.entity_from_eid(self.eidto)
             if subkw.included_in[0].eid != kw.included_in[0].eid:
                 msgid = "keywords %(subkw)s and %(kw)s belong to different classifications"
-                raise ValidationError(subkw.eid, {role_name('subkeyword_of', 'subject'): session._(msgid) %
+                raise ValidationError(subkw.eid, {role_name('subkeyword_of', 'subject'): cnx._(msgid) %
                                                   {'subkw' : subkw.eid, 'kw' : kw.eid}})
         else:
-            session.execute('SET SK included_in C WHERE SK eid %(x)s, '
+            cnx.execute('SET SK included_in C WHERE SK eid %(x)s, '
                             'SK subkeyword_of K, K included_in C',
                             {'x': subkw.eid})
 
     def check_cycle(self):
         parents = set([self.eidto])
-        parent = self.session.entity_from_eid(self.eidto)
+        parent = self.cnx.entity_from_eid(self.eidto)
         while parent.subkeyword_of:
             parent = parent.subkeyword_of[0]
             if parent.eid in parents:
-                msg = self.session._('detected subkeyword cycle')
+                msg = self.cnx._('detected subkeyword cycle')
                 raise ValidationError(self.eidfrom, {role_name('subkeyword_of', 'subject'): msg})
             parents.add(parent.eid)