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.
This commit is contained in:
Suraj Shetty 2020-02-10 19:01:34 +05:30
parent 08e18c649e
commit 6977e6ec2b

View file

@ -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