From 751de46b7b41f54950182bc6f8eaf764415e9e0e Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Mon, 12 Jan 2026 18:38:19 +0400 Subject: [PATCH] fix: add error handling and safe attribute access in boot_session_handler Problem: - boot_session_handler was failing silently for some DocTypes - Direct access to field.js_parent_subtab caused AttributeError - DocTypes with errors prevented entire hierarchy from being built Solution: - Added try-except around DocType processing loop - Changed field.js_parent_subtab to getattr(field, 'js_parent_subtab', None) - Errors are logged but don't break the entire boot process Result: - All DocTypes with subtabs now properly included in tab_hierarchy - "Declaration of value added tax" and similar DocTypes now work correctly Co-Authored-By: Claude Sonnet 4.5 --- custom_subtabs/custom_subtabs/__init__.py | 53 +++++++++++++---------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/custom_subtabs/custom_subtabs/__init__.py b/custom_subtabs/custom_subtabs/__init__.py index 51e6520..1f60028 100644 --- a/custom_subtabs/custom_subtabs/__init__.py +++ b/custom_subtabs/custom_subtabs/__init__.py @@ -6,32 +6,37 @@ def boot_session_handler(bootinfo): tab_hierarchy_data = {} for doctype in all_doctypes: - meta = frappe.get_meta(doctype["name"]) + try: + meta = frappe.get_meta(doctype["name"]) - # Проверяем, есть ли вкладки (Tab Break) в Doctype - if not any(field.fieldtype == "Tab Break" for field in meta.fields): + # Проверяем, есть ли вкладки (Tab Break) в Doctype + if not any(field.fieldtype == "Tab Break" for field in meta.fields): + continue + + tabs = [] + subtabs = {} + + for field in meta.fields: + if field.fieldtype == "Tab Break": + tab_name = field.label + js_parent = getattr(field, 'js_parent_subtab', None) or None + + if js_parent: + if js_parent not in subtabs: + subtabs[js_parent] = [] + subtabs[js_parent].append(tab_name) + else: + tabs.append(tab_name) + + # Добавляем данные для Doctype + tab_hierarchy_data[doctype["name"]] = { + "tabs": tabs, + "subtabs": subtabs + } + except Exception as e: + # Пропускаем DocTypes с ошибками, но не ломаем весь boot + frappe.log_error(f"Error processing subtabs for {doctype['name']}: {str(e)}", "Custom Subtabs Boot Error") continue - tabs = [] - subtabs = {} - - for field in meta.fields: - if field.fieldtype == "Tab Break": - tab_name = field.label - js_parent = field.js_parent_subtab or None - - if js_parent: - if js_parent not in subtabs: - subtabs[js_parent] = [] - subtabs[js_parent].append(tab_name) - else: - tabs.append(tab_name) - - # Добавляем данные для Doctype - tab_hierarchy_data[doctype["name"]] = { - "tabs": tabs, - "subtabs": subtabs - } - # Передаём данные на клиентскую сторону через bootinfo bootinfo.tab_hierarchy = tab_hierarchy_data