From 0aaaca9b1a8b5ab5ac9d6b9ce43fa4b3176cd3ce Mon Sep 17 00:00:00 2001 From: pratu16x7 Date: Thu, 7 Sep 2017 16:02:25 +0530 Subject: [PATCH 1/4] [fix] ignore results with non-existent doctypes --- frappe/patches.txt | 1 + frappe/patches/v8_10/__init__.py | 0 .../delete_static_web_page_from_global_search.py | 5 +++++ frappe/utils/global_search.py | 11 ++++++++--- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 frappe/patches/v8_10/__init__.py create mode 100644 frappe/patches/v8_10/delete_static_web_page_from_global_search.py diff --git a/frappe/patches.txt b/frappe/patches.txt index ce0a749126..28bc5cb574 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -192,3 +192,4 @@ frappe.patches.v8_5.delete_email_group_member_with_invalid_emails frappe.patches.v8_x.update_user_permission frappe.patches.v8_5.patch_event_colors frappe.patches.v8_7.update_email_queue_status +frappe.patches.v8_10.delete_static_web_page_from_global_search diff --git a/frappe/patches/v8_10/__init__.py b/frappe/patches/v8_10/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/patches/v8_10/delete_static_web_page_from_global_search.py b/frappe/patches/v8_10/delete_static_web_page_from_global_search.py new file mode 100644 index 0000000000..336562c157 --- /dev/null +++ b/frappe/patches/v8_10/delete_static_web_page_from_global_search.py @@ -0,0 +1,5 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.db.sql("""delete from `__global_search` where doctype='Static Web Page'"""); \ No newline at end of file diff --git a/frappe/utils/global_search.py b/frappe/utils/global_search.py index ea76247300..f2ba1069ce 100644 --- a/frappe/utils/global_search.py +++ b/frappe/utils/global_search.py @@ -307,9 +307,14 @@ def search(text, start=0, limit=20, doctype=""): limit {start}, {limit}'''.format(start=start, limit=limit), (doctype, text), as_dict=True) for r in results: - if frappe.get_meta(r.doctype).image_field: - doc = frappe.get_doc(r.doctype, r.name) - r.image = doc.get(doc.meta.image_field) + if not frappe.db.exists("Doctype", r.doctype): + continue + try: + if frappe.get_meta(r.doctype).image_field: + doc = frappe.get_doc(r.doctype, r.name) + r.image = doc.get(doc.meta.image_field) + except: + pass return results From 1a3d0bb4590ac1461a90d71d2963344e0d9aad23 Mon Sep 17 00:00:00 2001 From: pratu16x7 Date: Fri, 8 Sep 2017 06:39:18 +0530 Subject: [PATCH 2/4] [fix] clear messages on exception --- frappe/utils/global_search.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frappe/utils/global_search.py b/frappe/utils/global_search.py index f2ba1069ce..fa7c464831 100644 --- a/frappe/utils/global_search.py +++ b/frappe/utils/global_search.py @@ -307,13 +307,12 @@ def search(text, start=0, limit=20, doctype=""): limit {start}, {limit}'''.format(start=start, limit=limit), (doctype, text), as_dict=True) for r in results: - if not frappe.db.exists("Doctype", r.doctype): - continue try: if frappe.get_meta(r.doctype).image_field: doc = frappe.get_doc(r.doctype, r.name) r.image = doc.get(doc.meta.image_field) except: + frappe.clear_messages() pass return results From f66cfcece5fe4e68cc624fa04231cddf9791161c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 8 Sep 2017 09:06:32 +0530 Subject: [PATCH 3/4] Update global_search.py --- frappe/utils/global_search.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frappe/utils/global_search.py b/frappe/utils/global_search.py index fa7c464831..35e9d40758 100644 --- a/frappe/utils/global_search.py +++ b/frappe/utils/global_search.py @@ -309,8 +309,7 @@ def search(text, start=0, limit=20, doctype=""): for r in results: try: if frappe.get_meta(r.doctype).image_field: - doc = frappe.get_doc(r.doctype, r.name) - r.image = doc.get(doc.meta.image_field) + r.image = frappe.db.get_value(r.doctype, r.name, frappe.get_meta(r.doctype).image_field) except: frappe.clear_messages() pass From 9cee53c33f12ea2856bc009b98b7a5e388fdcc24 Mon Sep 17 00:00:00 2001 From: pratu16x7 Date: Fri, 8 Sep 2017 16:03:51 +0530 Subject: [PATCH 4/4] [fix] specify exception --- frappe/utils/global_search.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frappe/utils/global_search.py b/frappe/utils/global_search.py index 35e9d40758..f9a07e3212 100644 --- a/frappe/utils/global_search.py +++ b/frappe/utils/global_search.py @@ -310,9 +310,8 @@ def search(text, start=0, limit=20, doctype=""): try: if frappe.get_meta(r.doctype).image_field: r.image = frappe.db.get_value(r.doctype, r.name, frappe.get_meta(r.doctype).image_field) - except: + except Exception: frappe.clear_messages() - pass return results