From 7f6a234cf7883f360b60fe05932e11ce7da8cf0a Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 1 Jul 2026 09:10:16 +0530 Subject: [PATCH] fix(stock): pin get_item_price tie-break so MariaDB and Postgres agree get_item_price ORDER BYs valid_from/batch_no/uom/party then LIMIT 1 with no unique key. Two Item Price rows tied on all of those but differing price_list_rate would be picked arbitrarily -- MariaDB and Postgres can return a different rate. Append a name tiebreaker; for exact ties MariaDB's pick was already undefined, so its output is preserved. Co-Authored-By: Claude Opus 4.8 --- erpnext/stock/get_item_details.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 33aceab0bf3..aa9750f7523 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1269,6 +1269,10 @@ def get_item_price( & (IfNull(ip.valid_upto, "2500-12-31") >= pctx.transaction_date) ) + # Final unique tiebreaker: rows tied on every sort key above (same valid_from/batch/uom/party) + # would otherwise be picked arbitrarily -- MariaDB and Postgres can differ. Pin the pick. + query = query.orderby(ip.name, order=frappe.qb.desc) + return query.run(as_dict=True)