[repository] 'session' argument is always given to extid2eid, make it mandatory and simplify code accordingly
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 04 Apr 2014 14:48:51 +0200
changeset 9662 f13ae1fea212
parent 9661 c170ec8a4525
child 9663 f512d72a1dc4
[repository] 'session' argument is always given to extid2eid, make it mandatory and simplify code accordingly
server/repository.py
server/sources/__init__.py
server/sources/ldapfeed.py
--- a/server/repository.py	Fri Mar 28 14:59:33 2014 +0100
+++ b/server/repository.py	Fri Apr 04 14:48:51 2014 +0200
@@ -1029,7 +1029,7 @@
             args[key] = int(args[key])
         return tuple(cachekey)
 
-    def extid2eid(self, source, extid, etype, session=None, insert=True,
+    def extid2eid(self, source, extid, etype, session, insert=True,
                   complete=True, commit=True, sourceparams=None):
         """Return eid from a local id. If the eid is a negative integer, that
         means the entity is known but has been copied back to the system source
@@ -1058,15 +1058,10 @@
         except KeyError:
             pass
         free_cnxset = False
-        if session is None:
-            session = self.internal_session()
-            free_cnxset = True
         eid = self.system_source.extid2eid(session, extid)
         if eid is not None:
             self._extid_cache[extid] = eid
             self._type_source_cache[eid] = (etype, extid, source.uri)
-            if free_cnxset:
-                session.free_cnxset()
             return eid
         if not insert:
             return
--- a/server/sources/__init__.py	Fri Mar 28 14:59:33 2014 +0100
+++ b/server/sources/__init__.py	Fri Apr 04 14:48:51 2014 +0200
@@ -451,7 +451,7 @@
 
 
     @deprecated('[3.13] use extid2eid(source, value, etype, session, **kwargs)')
-    def extid2eid(self, value, etype, session=None, **kwargs):
+    def extid2eid(self, value, etype, session, **kwargs):
         return self.repo.extid2eid(self, value, etype, session, **kwargs)
 
 
--- a/server/sources/ldapfeed.py	Fri Mar 28 14:59:33 2014 +0100
+++ b/server/sources/ldapfeed.py	Fri Apr 04 14:48:51 2014 +0200
@@ -252,7 +252,7 @@
         except Exception:
             self.error('while trying to authenticate %s', user, exc_info=True)
             raise AuthenticationError()
-        eid = self.repo.extid2eid(self, user['dn'], 'CWUser', session=cnx, insert=False)
+        eid = self.repo.extid2eid(self, user['dn'], 'CWUser', cnx, insert=False)
         if eid < 0:
             # user has been moved away from this source
             raise AuthenticationError()