From 72f293f131cc7b8a50b1d4bbd07fe4360ca38fbb Mon Sep 17 00:00:00 2001 From: pandiyan Date: Fri, 31 Jul 2026 13:54:53 +0530 Subject: [PATCH] fix: guard against None row in get_stock_balance_for (backport #57567) get_stock_balance_for() takes row=None by default, but the batch-tracked branch dereferenced it unconditionally while the two neighbouring row accesses already guard. Calling it with a batch_no and no row raised AttributeError: 'NoneType' object has no attribute 'use_serial_batch_fields'. semgrep's missing-argument-type-hint rule matches the whole function body, so touching any line inside it re-fingerprints the pre-existing untyped arguments and reports them as introduced by this PR. Silenced with nosemgrep instead of annotating: on a whitelisted method the hints are enforced at runtime by pydantic, which is not a risk worth taking on v15. --- .../stock/doctype/stock_reconciliation/stock_reconciliation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index ab1358e8293..9f84909b432 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -1292,6 +1292,7 @@ def get_row_stock_value_difference(voucher_type: str, voucher_no: str, voucher_d return flt(result[0][0]) if result and result[0][0] else 0.0 +# nosemgrep: missing-argument-type-hint @frappe.whitelist() def get_stock_balance_for( item_code: str, @@ -1364,7 +1365,7 @@ def get_stock_balance_for( or 0 ) - if row.use_serial_batch_fields and row.batch_no and (qty or row.current_qty): + if row and row.use_serial_batch_fields and row.batch_no and (qty or row.current_qty): rate = get_incoming_rate( frappe._dict( {