[repository] 'session' argument is always given to type[_and_source]_from_eid, make it mandatory and simplify code accordingly
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 04 Apr 2014 12:39:59 +0200
changeset 9663 f512d72a1dc4
parent 9662 f13ae1fea212
child 9664 5ef5494b6b0b
[repository] 'session' argument is always given to type[_and_source]_from_eid, make it mandatory and simplify code accordingly
server/repository.py
server/test/unittest_migractions.py
--- a/server/repository.py	Fri Apr 04 14:48:51 2014 +0200
+++ b/server/repository.py	Fri Apr 04 12:39:59 2014 +0200
@@ -971,7 +971,7 @@
     # * correspondance between eid and (type, source)
     # * correspondance between eid and local id (i.e. specific to a given source)
 
-    def type_and_source_from_eid(self, eid, session=None):
+    def type_and_source_from_eid(self, eid, session):
         """return a tuple `(type, extid, actual source uri)` for the entity of
         the given `eid`
         """
@@ -982,17 +982,8 @@
         try:
             return self._type_source_cache[eid]
         except KeyError:
-            if session is None:
-                session = self.internal_session()
-                free_cnxset = True
-            else:
-                free_cnxset = False
-            try:
-                etype, extid, auri = self.system_source.eid_type_source(
-                    session, eid)
-            finally:
-                if free_cnxset:
-                    session.free_cnxset()
+            etype, extid, auri = self.system_source.eid_type_source(session,
+                                                                    eid)
             self._type_source_cache[eid] = (etype, extid, auri)
             return etype, extid, auri
 
@@ -1010,7 +1001,7 @@
             rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None)
             self.system_source.clear_eid_cache(eid, etype)
 
-    def type_from_eid(self, eid, session=None):
+    def type_from_eid(self, eid, session):
         """return the type of the entity with id <eid>"""
         return self.type_and_source_from_eid(eid, session)[0]
 
--- a/server/test/unittest_migractions.py	Fri Apr 04 14:48:51 2014 +0200
+++ b/server/test/unittest_migractions.py	Fri Apr 04 12:39:59 2014 +0200
@@ -262,7 +262,7 @@
 
     def test_rename_entity_type(self):
         entity = self.mh.create_entity('Old', name=u'old')
-        self.repo.type_and_source_from_eid(entity.eid)
+        self.repo.type_and_source_from_eid(entity.eid, entity._cw)
         self.mh.cmd_rename_entity_type('Old', 'New')
         self.mh.cmd_rename_attribute('New', 'name', 'new_name')