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


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

request failed with status 404
sourcemap URL:

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/ in line 205

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

Created a GitHub issue: