[FIX] do not keep connections to template1, template0 and postgres in the connection...
authorChristophe Simonis <chs@openerp.com>
Fri, 19 Mar 2010 15:07:24 +0000 (16:07 +0100)
committerChristophe Simonis <chs@openerp.com>
Fri, 19 Mar 2010 15:07:24 +0000 (16:07 +0100)
lp bug: https://launchpad.net/bugs/314973 fixed

bzr revid: chs@openerp.com-20100319150724-g19loevglu1daggq

bin/sql_db.py

index 9398a42..4ddb7f6 100644 (file)
@@ -186,7 +186,8 @@ class Cursor(object):
         # part because browse records keep a reference to the cursor.
         del self._obj
         self.__closed = True
-        self._pool.give_back(self._cnx)
+        keep_in_pool = self.dbname not in ('template1', 'template0', 'postgres')
+        self._pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
 
     @check
     def autocommit(self, on):
@@ -268,12 +269,14 @@ class ConnectionPool(object):
         return result
 
     @locked
-    def give_back(self, connection):
+    def give_back(self, connection, keep_in_pool=True):
         self._debug('Give back connection to %s' % (connection.dsn,))
         for i, (cnx, used) in enumerate(self._connections):
             if cnx is connection:
                 self._connections.pop(i)
-                self._connections.append((cnx, False))
+                if keep_in_pool:
+                    self._connections.append((cnx, False))
+                    self._debug('Put connection to %s in pool' % (cnx.dsn,))
                 break
         else:
             raise PoolError('This connection does not below to the pool')