From 0fe764c9b8564205e40ae91b22aa4e88c1e6bb03 Mon Sep 17 00:00:00 2001 From: gavin Date: Mon, 23 May 2022 14:24:26 +0530 Subject: [PATCH] fix: Depend on replica details being there for Replica ConnectionPool This logic mirror how replica connections are handled --- frappe/database/mariadb/database.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frappe/database/mariadb/database.py b/frappe/database/mariadb/database.py index fd9ecd1f96..595a02db6f 100644 --- a/frappe/database/mariadb/database.py +++ b/frappe/database/mariadb/database.py @@ -102,19 +102,18 @@ class MariaDBConnectionUtil: 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: self.close_connection_pools() return self.create_connection() - is_read_only_conn = hasattr(frappe.local, "primary_db") + read_only = frappe.conf.read_from_replica and frappe.conf.replica_host if frappe.local.site not in _SITE_POOLS: - site_pool = self.create_connection_pool(read_only=is_read_only_conn) + site_pool = self.create_connection_pool(read_only=read_only) else: - site_pool = self.get_connection_pool(read_only=is_read_only_conn) + site_pool = self.get_connection_pool(read_only=read_only) try: conn = site_pool.get_connection()