From f66ef869fcce3d8b223d2ecdebfe238730ab07b5 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 21 Jun 2026 10:25:30 +0530 Subject: [PATCH 1/2] test(stock): use db-agnostic index introspection in Bin index test test_index_exists used `frappe.db.sql("show index from tabBin ...")`. "SHOW INDEX" is MySQL-only syntax and errors on Postgres (syntax error at "from"), so the test could not run there. Use the db-agnostic frappe.db.has_index("tabBin", "unique_item_warehouse") instead. Co-Authored-By: Claude Opus 4.8 (1M context) --- erpnext/stock/doctype/bin/test_bin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/bin/test_bin.py b/erpnext/stock/doctype/bin/test_bin.py index ef21bcf7833..e66e453aca1 100644 --- a/erpnext/stock/doctype/bin/test_bin.py +++ b/erpnext/stock/doctype/bin/test_bin.py @@ -27,6 +27,6 @@ class TestBin(ERPNextTestSuite): self.assertEqual(bin.item_code, item_code) def test_index_exists(self): - indexes = frappe.db.sql("show index from tabBin where Non_unique = 0", as_dict=1) - if not any(index.get("Key_name") == "unique_item_warehouse" for index in indexes): + # has_index is db-agnostic; raw "SHOW INDEX" is MySQL-only and errors on Postgres + if not frappe.db.has_index("tabBin", "unique_item_warehouse"): self.fail("Expected unique index on item-warehouse") From 9fe2202f396db49edcb26d1a09e93accd3d7a4d3 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 21 Jun 2026 10:25:32 +0530 Subject: [PATCH 2/2] test(stock): use db-agnostic index introspection in Item index test test_index_creation used `frappe.db.sql("show index from tabItem")` and the MySQL-only result key "Column_name". "SHOW INDEX" errors on Postgres, so the test could not run there. Use the db-agnostic frappe.db.get_column_index("tabItem", column) (checking both unique and non-unique single-column indexes) instead. Co-Authored-By: Claude Opus 4.8 (1M context) --- erpnext/stock/doctype/item/test_item.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 5273b792b9b..4b6537edb87 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -778,10 +778,13 @@ class TestItem(ERPNextTestSuite): def test_index_creation(self): "check if index is getting created in db" - indices = frappe.db.sql("show index from tabItem", as_dict=1) + # get_column_index is db-agnostic; raw "SHOW INDEX" is MySQL-only and errors on Postgres expected_columns = {"item_code", "item_name", "item_group"} - for index in indices: - expected_columns.discard(index.get("Column_name")) + for column in list(expected_columns): + if frappe.db.get_column_index("tabItem", column, unique=False) or frappe.db.get_column_index( + "tabItem", column, unique=True + ): + expected_columns.discard(column) if expected_columns: self.fail(f"Expected db index on these columns: {', '.join(expected_columns)}")