From 72046d3688c888dddd24edf4c378054ab42e8576 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 21 Jun 2026 15:29:30 +0530 Subject: [PATCH] test(stock): savepoint around expected duplicate Bin insert (Postgres) The deliberate UniqueValidationError from the second Bin insert aborts the transaction on Postgres, so the following _create_bin() (which takes its own savepoint) failed with InFailedSqlTransaction. Wrap the expected-failure insert in a savepoint and roll back to it, mirroring _create_bin's 'preserve transaction in postgres' pattern. No-op on MariaDB. --- erpnext/stock/doctype/bin/test_bin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/stock/doctype/bin/test_bin.py b/erpnext/stock/doctype/bin/test_bin.py index e66e453aca1..81b60d6ce19 100644 --- a/erpnext/stock/doctype/bin/test_bin.py +++ b/erpnext/stock/doctype/bin/test_bin.py @@ -19,8 +19,10 @@ class TestBin(ERPNextTestSuite): bin1.insert() bin2 = frappe.get_doc(doctype="Bin", item_code=item_code, warehouse=warehouse) + frappe.db.savepoint("dup_bin") with self.assertRaises(frappe.UniqueValidationError): bin2.insert() + frappe.db.rollback(save_point="dup_bin") # preserve transaction in postgres # util method should handle it bin = _create_bin(item_code, warehouse)