From f6d003963c2d1046ae65e32b5ced9ef578be0782 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 11 Apr 2024 11:51:40 +0530 Subject: [PATCH] fix: show warning for pending migrations (#25908) * Revert "fix: limit title length on form (#25880)" This reverts commit 28177c8574e13dea992db170776b3c72e8522376. * fix: show warning for pending migrations --- frappe/core/doctype/doctype/doctype.js | 1 + frappe/core/doctype/doctype/doctype.py | 21 ++++++++++++++++++++- frappe/public/js/frappe/ui/page.html | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index ebc4d85d0b..f672db1f92 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -6,6 +6,7 @@ frappe.ui.form.on("DocType", { if (frm.is_new() && !frm.doc?.fields) { frappe.listview_settings["DocType"].new_doctype_dialog(); } + frm.call("check_pending_migration"); }, before_save: function (frm) { diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 7c29792778..95a723188f 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -6,6 +6,7 @@ import json import os import re import shutil +from pathlib import Path from typing import TYPE_CHECKING, Union import frappe @@ -32,7 +33,7 @@ from frappe.modules import get_doc_path, make_boilerplate from frappe.modules.import_file import get_file_path from frappe.permissions import ALL_USER_ROLE, AUTOMATIC_ROLES, SYSTEM_USER_ROLE from frappe.query_builder.functions import Concat -from frappe.utils import cint, flt, is_a_property, random_string +from frappe.utils import cint, flt, get_datetime, is_a_property, random_string from frappe.website.utils import clear_cache if TYPE_CHECKING: @@ -1021,6 +1022,24 @@ class DocType(Document): validate_route_conflict(self.doctype, self.name) + @frappe.whitelist() + def check_pending_migration(self) -> bool: + """Checks if all migrations are applied on doctype.""" + if self.is_new() or self.custom: + return + + file = Path(get_file_path(frappe.scrub(self.module), self.doctype, self.name)) + content = json.loads(file.read_text()) + if content.get("modified") and get_datetime(self.modified) != get_datetime(content.get("modified")): + frappe.msgprint( + _( + "This doctype has pending migrations, run 'bench migrate' before modifying the doctype to avoid losing changes." + ), + alert=True, + indicator="yellow", + ) + return True + def validate_series(dt, autoname=None, name=None): """Validate if `autoname` property is correctly set.""" diff --git a/frappe/public/js/frappe/ui/page.html b/frappe/public/js/frappe/ui/page.html index df87ad84bb..55083e1b9a 100644 --- a/frappe/public/js/frappe/ui/page.html +++ b/frappe/public/js/frappe/ui/page.html @@ -17,7 +17,7 @@
-
+