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.
This commit is contained in:
Mihir Kandoi
2026-06-21 15:29:30 +05:30
parent b97a0c9a13
commit 72046d3688

View File

@@ -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)