From ce2e7fb7ee0ccdd4486441ec406fbb7c9422b7d5 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 21 Jun 2026 04:56:00 +0530 Subject: [PATCH] refactor(startup): convert boot_session raw SQL to ORM (Postgres-valid) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit boot_session used raw `frappe.db.sql`, including a MySQL-only `ifnull(account_type, '')` over Party Type that is invalid on Postgres. - customer_count: `SELECT count(*)` → `frappe.db.count` - setup_complete: `SELECT name ... LIMIT 1` → `frappe.db.get_all(limit=1)` - companies: raw select → `frappe.get_all`, preserving the `:Company` virtual-doc marker - party_account_types: `ifnull(account_type,'')` → `frappe.get_all` with a Python `account_type or ""`, which collapses NULL→'' and ''→'' identically on both engines (handles Postgres storing '' as NULL) Adds a test (no test file existed) that runs boot_session and asserts the company list and party_account_types are populated, on both engines. Co-Authored-By: Claude Opus 4.8 (1M context) --- erpnext/startup/boot.py | 1 + erpnext/startup/test_boot.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 erpnext/startup/test_boot.py diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py index a451995531c..64349479a08 100644 --- a/erpnext/startup/boot.py +++ b/erpnext/startup/boot.py @@ -54,6 +54,7 @@ def boot_session(bootinfo): "country", "exchange_gain_loss_account", ], + limit_page_length=0, # intentionally unbounded: all companies are needed for boot ) for company in companies: company.doctype = ":Company" diff --git a/erpnext/startup/test_boot.py b/erpnext/startup/test_boot.py new file mode 100644 index 00000000000..05e3fa7ee6a --- /dev/null +++ b/erpnext/startup/test_boot.py @@ -0,0 +1,22 @@ +# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe + +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBoot(ERPNextTestSuite): + def test_boot_session_populates_companies_and_party_types(self): + # boot_session reads Customer count, Company list and Party Type account types via ORM/qb + # (formerly raw SQL with ifnull, which is invalid on Postgres). Exercises that on both engines. + from erpnext.startup.boot import boot_session + + bootinfo = frappe._dict(sysdefaults=frappe._dict(), page_info=frappe._dict(), docs=[]) + boot_session(bootinfo) + + self.assertIsInstance(bootinfo.customer_count, int) + self.assertIn("party_account_types", bootinfo) + + company_docs = [d for d in bootinfo.docs if d.get("doctype") == ":Company"] + self.assertTrue(any(d.get("name") == "_Test Company" for d in company_docs))