Cannot use sub-query or function in fields

When I go to erased documents
(Installed Apps
ERPNext: v10.1.5 (master)
Frappe Framework: v10.1.2 (master)

I get this message:

Cannot use sub-query or function in fields

Trace:

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 62, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 939, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/reportview.py”, line 21, in get
data = compress(execute(**args), args = args)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/reportview.py”, line 26, in execute
return DatabaseQuery(doctype).execute(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 88, in execute
result = self.build_and_run()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 100, in build_and_run
args = self.prepare_args()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 116, in prepare_args
self.sanitize_fields()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 205, in sanitize_fields
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 200, in raise_exception
frappe.throw(
(‘Cannot use sub-query or function in fields’), frappe.DataError)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 323, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 309, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 282, in _raise_exception
raise raise_exception(encode(msg))
DataError: Cannot use sub-query or function in fields

request failed with status 404
http://localhost:8080/assets/css/desk.min.css?ver=1520358421.76
sourcemap URL: awesomplete.css.map

the same issue, what is this mean Cannot use sub-query or function in fields

I have the same issue reproducable over several ERPNext installations.

Steps to reproduce:

  • in the search bar, type “Deleted documents list” and open the deleted documents.
  • the following error message appears

This occurs also on refresh and filters of this list. It is “only” annoying, the data is represented correctly.

It seems like the error is caused by this code:

count(`tabDeleted Document`.name) as total_count

This hits the regex filter in frappe/model/db_query.py in line 205

blacklisted_keywords = ['select', 'create', 'insert', 'delete', 'drop', 'update', 'case']
(...)
if any(keyword in field.lower() for keyword in blacklisted_keywords):
    _raise_exception()

Created a GitHub issue: