Merge pull request #35601 from AarDG10/fix-fallback-for-col-name-build

fix(data import): consider fieldname if label is null for col_build
This commit is contained in:
Aarol D'Souza 2026-01-05 15:50:49 +05:30 committed by GitHub
commit 9bd4194a43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View file

@ -1153,7 +1153,8 @@ def build_fields_dict_for_column_matching(parent_doctype):
doctypes = [(parent_doctype, None)] + [(df.options, df) for df in parent_meta.get_table_fields()]
for doctype, table_df in doctypes:
translated_table_label = _(table_df.label) if table_df else None
table_ref = (table_df.label or table_df.fieldname) if table_df else None
translated_table_label = _(table_ref) if table_ref else None
# name field
name_df = frappe._dict(
@ -1175,7 +1176,7 @@ def build_fields_dict_for_column_matching(parent_doctype):
else:
name_headers = (
f"{table_df.fieldname}.name", # fieldname
f"ID ({table_df.label})", # label
f"ID ({table_ref})", # label
"{} ({})".format(_("ID"), translated_table_label), # translated label
)
@ -1229,7 +1230,7 @@ def build_fields_dict_for_column_matching(parent_doctype):
# fieldname
f"{table_df.fieldname}.{df.fieldname}",
# label
f"{label} ({table_df.label})",
f"{label} ({table_ref})",
# translated label
f"{translated_label} ({translated_table_label})",
):

View file

@ -1,7 +1,7 @@
# Copyright (c) 2019, Frappe Technologies and Contributors
# License: MIT. See LICENSE
import frappe
from frappe.core.doctype.data_import.importer import Importer
from frappe.core.doctype.data_import.importer import Importer, build_fields_dict_for_column_matching
from frappe.tests import IntegrationTestCase
from frappe.tests.test_query_builder import db_type_is, unimplemented_for
from frappe.utils import format_duration, getdate
@ -146,6 +146,22 @@ class TestImporter(IntegrationTestCase):
self.assertEqual(updated_doc.table_field_1[0].child_description, "child description")
self.assertEqual(updated_doc.table_field_1_again[0].child_title, "child title again")
def test_data_import_without_label(self):
"""Test fallback to fieldname when label is not set for a table."""
meta = frappe.get_meta(doctype_name)
table_field = meta.get_field("table_field_1")
original_label = table_field.label
table_field.label = None
fields_dict = build_fields_dict_for_column_matching(doctype_name)
expected_key = "Child Title (table_field_1)"
self.assertIn(
expected_key, fields_dict, f"Fallback failed: '{expected_key}' not found in mapping dict"
)
expected_id_key = "ID (table_field_1)"
self.assertIn(expected_id_key, fields_dict, "ID fallback failed")
table_field.label = original_label # maintain sanity in test env
def get_importer(self, doctype, import_file, update=False, use_sniffer=False):
data_import = frappe.new_doc("Data Import")
data_import.import_type = "Insert New Records" if not update else "Update Existing Records"