Skip to content

fix(settings): render Attach field name when value is a dict#2470

Open
walidsaleh wants to merge 2 commits into
frappe:developfrom
walidsaleh:fix-lms-setting-fields-attach-dict
Open

fix(settings): render Attach field name when value is a dict#2470
walidsaleh wants to merge 2 commits into
frappe:developfrom
walidsaleh:fix-lms-setting-fields-attach-dict

Conversation

@walidsaleh

Copy link
Copy Markdown

Summary

Fix the generic SettingFields.vue template so it renders the file name of an Attach / AttachImage field even when the value is a dict (as returned by frappe.get_doc().as_dict()), not just a string.

This unblocks editing for any settings modal that uses SettingFields and has a previously-saved Attach field, e.g. Payment Gateway.header_img, Website Settings.banner_image.

Fixes #2417

Changes

One-line guard in frontend/src/components/Settings/SettingFields.vue:63:

<!-- before -->
{{ data[field.name].split('/').pop() }}

<!-- after -->
{{ typeof data[field.name] === 'string'
    ? data[field.name].split('/').pop()
    : (data[field.name]?.file_name || '') }}

Why

frappe.get_doc(...).as_dict() (used by lms.lms.api.get_payment_gateway_details and similar endpoints) serializes Attach / AttachImage fields as objects with file_url, file_name, file_size, etc. The template was assuming a string and calling .split unconditionally, which threw on the first open of any settings modal that had a saved Attach field, breaking the entire modal.

Test plan

  • Open Desk → Payment Gateway → edit a gateway that has a logo uploaded. Modal should render without throwing, and the filename should be visible.
  • Open LMS Settings → any tab that has an Attach field. Should render without throwing.
  • Open a fresh modal, upload a new file. The new file URL should be visible in the preview (existing behaviour, preserved).

walidsaleh and others added 2 commits June 13, 2026 17:44
The template assumed data[field.name] was a string and called
.split on it. But frappe.get_doc().as_dict() serializes
Attach / AttachImage fields as objects with file_url, file_name,
etc. So the first time a user opened a settings modal that
had a previously-saved Attach field, the template threw
"TypeError: ... .split is not a function" and broke the
entire modal (no save possible, no field editable).

Guard against the non-string case by checking typeof first.
If the value is a string, split and pop as before. If it is a
dict (the as_dict round-trip case), use file_name. Falls back
to empty string in the unlikely case neither shape matches.

Fixes frappe#2417
@raizasafeel

Copy link
Copy Markdown
Contributor

Hey, could you lint the code as per contribution guidelines:
https://github.com/frappe/erpnext/wiki/Pull-Request-Checklist#linting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants