From 614bb642ef343cfd106812f4af96d596e6cbb579 Mon Sep 17 00:00:00 2001 From: Ayaan Ahmad Date: Sat, 17 Jan 2026 21:29:48 +0530 Subject: [PATCH] refactor(model): simplify prefetch per szufisher's suggestion - Remove fetch_if_empty check from prefetch phase - Fetch ALL fields, let base_document.py handle fetch_if_empty - Avoids DRY violation (same logic in two places) - Efficiency difference is negligible --- frappe/model/document.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/frappe/model/document.py b/frappe/model/document.py index b45b62a4d2..e1d5bc0e64 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -1179,11 +1179,9 @@ class Document(BaseDocument): prefetch_map[doctype]["names"].add(docname) - # Collect fetch_from fields + # Collect fetch_from fields - fetch ALL, let base_document handle fetch_if_empty for fetch_df in doc.meta.get_fields_to_fetch(df.fieldname): - if not fetch_df.get("fetch_if_empty") or ( - fetch_df.get("fetch_if_empty") and not doc.get(fetch_df.fieldname) - ): + if fetch_df.get("fetch_from"): source_field = fetch_df.fetch_from.split(".")[-1] prefetch_map[doctype]["fields"].add(source_field)