From 6977e6ec2bb9fb2c9ba7ba1c7b7005e11fe2ec93 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Mon, 10 Feb 2020 19:01:34 +0530 Subject: [PATCH] fix: Throw "Invalid Filter Value" error on getting TypeError TypeError with message "'NoneType' object is not iterable" will mostly occur if a link field value does not exist. --- frappe/core/page/dashboard/dashboard.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/frappe/core/page/dashboard/dashboard.py b/frappe/core/page/dashboard/dashboard.py index 1f4eaee783..3496948d98 100644 --- a/frappe/core/page/dashboard/dashboard.py +++ b/frappe/core/page/dashboard/dashboard.py @@ -3,7 +3,8 @@ from __future__ import unicode_literals import json import frappe -from frappe.utils import add_to_date +from frappe import _ +from frappe.utils import add_to_date, get_link_to_form def cache_source(function): @@ -29,7 +30,21 @@ def cache_source(function): return wrapper def generate_and_cache_results(chart, chart_name, function, cache_key): - results = function(chart_name = chart_name) + try: + results = function(chart_name = chart_name) + except TypeError as e: + if e.message == "'NoneType' object is not iterable": + # Probably because of invalid link filter + # + # Note: Do not try to find the right way of doing this because + # it results in an inelegant & inefficient solution + # ref: https://github.com/frappe/frappe/pull/9403 + frappe.throw(_('Please check the filter values set for Dashboard Chart: {}').format( + get_link_to_form(chart.doctype, chart.name)), title=_('Invalid Filter Value')) + return + else: + raise + frappe.cache().set_value(cache_key, json.dumps(results, default=str)) frappe.db.set_value("Dashboard Chart", chart_name, "last_synced_on", frappe.utils.now(), update_modified = False) return results