Browse Source

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.
version-14
Suraj Shetty 5 years ago
parent
commit
6977e6ec2b
1 changed files with 17 additions and 2 deletions
  1. +17
    -2
      frappe/core/page/dashboard/dashboard.py

+ 17
- 2
frappe/core/page/dashboard/dashboard.py 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


Loading…
Cancel
Save