mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-12 22:21:50 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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)}")
|
||||
|
||||
Reference in New Issue
Block a user