From 363708d7f2e161b0becb41e90c03bfb31a5f822d Mon Sep 17 00:00:00 2001 From: gavin Date: Mon, 23 May 2022 12:46:56 +0530 Subject: [PATCH] fix: frappe.conf.disable_database_connection_pooling For the times you don't want to use pooling ;) Calling get_connection/connect will close all pooled connections for the current process / worker! --- frappe/database/mariadb/database.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frappe/database/mariadb/database.py b/frappe/database/mariadb/database.py index f43f068e40..3f2580490d 100644 --- a/frappe/database/mariadb/database.py +++ b/frappe/database/mariadb/database.py @@ -145,9 +145,24 @@ class MariaDBDatabase(Database, MariaDBExceptionUtil): } def get_connection(self): + """Return MariaDB connection object. + + If frappe.conf.disable_database_connection_pooling is set, return a new connection + object and close existing pool if exists. Else, return a connection from the pool. + """ # get pooled connection global _SITE_POOLS + if frappe.conf.disable_database_connection_pooling: + if frappe.local.site in _SITE_POOLS: + pool = _SITE_POOLS[frappe.local.site] + try: + pool.close() + except Exception: + pass + _SITE_POOLS.pop(frappe.local.site, None) + return self.create_connection() + if frappe.local.site not in _SITE_POOLS: pool = mariadb.ConnectionPool( pool_name=f"{frappe.local.site}_conn_pool",