From cf52f5f9c6d6a6ceeedcf7333e51047809a8304e Mon Sep 17 00:00:00 2001 From: phot0n Date: Sun, 11 Sep 2022 22:29:42 +0530 Subject: [PATCH 1/3] fix: sync app dashboard on app install * chore: fix sync_dashboards' docstring (cherry picked from commit 51ac3e8a998adbc7f9a6083444ff0ad04de12cb5) --- frappe/installer.py | 2 ++ frappe/utils/dashboard.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frappe/installer.py b/frappe/installer.py index d7394ab3f2..4f1755c2a0 100644 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -11,6 +11,7 @@ import click import frappe from frappe.defaults import _clear_cache from frappe.utils import cint, is_git_url +from frappe.utils.dashboard import sync_dashboards def _is_scheduler_enabled() -> bool: @@ -301,6 +302,7 @@ def install_app(name, verbose=False, set_as_patched=True, force=False): sync_jobs() sync_fixtures(name) sync_customizations(name) + sync_dashboards(name) for after_sync in app_hooks.after_sync or []: frappe.get_attr(after_sync)() # diff --git a/frappe/utils/dashboard.py b/frappe/utils/dashboard.py index 6acd63274e..125e0d2245 100644 --- a/frappe/utils/dashboard.py +++ b/frappe/utils/dashboard.py @@ -84,9 +84,10 @@ def get_dashboards_with_link(docname, doctype): def sync_dashboards(app=None): - """Import, overwrite fixtures from `[app]/fixtures`""" + """Import, overwrite dashboards from `[app]/[app]_dashboard`""" if not cint(frappe.db.get_single_value("System Settings", "setup_complete")): return + if app: apps = [app] else: From 5a61fcf28dee1b5c3e83952b9ba455c535f887d4 Mon Sep 17 00:00:00 2001 From: phot0n Date: Mon, 12 Sep 2022 00:38:55 +0530 Subject: [PATCH 2/3] fix: commit after app install Since we destroy the connection after app installation, mariadb implicitly rollsback the transaction hence committing upon successfull app installation to prevent data sync loss (cherry picked from commit 3539dacdf025ecc7c65036d8a55b99167380c5fa) --- frappe/commands/site.py | 3 +++ frappe/utils/fixtures.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index eb5a732f04..13f642ea76 100644 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -420,6 +420,9 @@ def install_app(context, apps, force=False): print(f"An error occurred while installing {app}{err_msg}") exit_code = 1 + if not exit_code: + frappe.db.commit() + frappe.destroy() sys.exit(exit_code) diff --git a/frappe/utils/fixtures.py b/frappe/utils/fixtures.py index 6b3166bfe6..821b1a1187 100644 --- a/frappe/utils/fixtures.py +++ b/frappe/utils/fixtures.py @@ -25,8 +25,6 @@ def sync_fixtures(app=None): frappe.flags.in_fixtures = False - frappe.db.commit() - def import_custom_scripts(app): """Import custom scripts from `[app]/fixtures/custom_scripts`""" From 99cb37c38db3609906fb0a599fb3ba29d27fc170 Mon Sep 17 00:00:00 2001 From: phot0n Date: Mon, 12 Sep 2022 16:03:06 +0530 Subject: [PATCH 3/3] fix: allow syncing of dashboard even if setup is not complete (cherry picked from commit 1d27f936e99dbe67d24c3cb501a01e59273b96b4) --- frappe/utils/dashboard.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/frappe/utils/dashboard.py b/frappe/utils/dashboard.py index 125e0d2245..0c60e817a3 100644 --- a/frappe/utils/dashboard.py +++ b/frappe/utils/dashboard.py @@ -85,13 +85,7 @@ def get_dashboards_with_link(docname, doctype): def sync_dashboards(app=None): """Import, overwrite dashboards from `[app]/[app]_dashboard`""" - if not cint(frappe.db.get_single_value("System Settings", "setup_complete")): - return - - if app: - apps = [app] - else: - apps = frappe.get_installed_apps() + apps = [app] if app else frappe.get_installed_apps() for app_name in apps: print(f"Updating Dashboard for {app_name}")