fix(reportview): remove redundant DISTINCT in get_count for postgres

This commit is contained in:
AarDG10 2025-11-06 10:54:07 +05:30
parent a4304124ec
commit 886b3b33e3
2 changed files with 2 additions and 4 deletions

View file

@ -60,9 +60,8 @@ def get_count() -> int | None:
return frappe.call(controller.get_count, args=args, **args)
args.distinct = sbool(args.distinct)
distinct = "distinct " if args.distinct else ""
args.limit = cint(args.limit)
fieldname = f"{distinct}`tab{args.doctype}`.name"
fieldname = f"`tab{args.doctype}`.name"
args.order_by = None
# args.limit is specified to avoid getting accurate count.

View file

@ -1244,7 +1244,6 @@ class TestDBQuery(IntegrationTestCase):
class TestReportView(IntegrationTestCase):
@run_only_if(db_type_is.MARIADB) # TODO: postgres name casting is messed up
def test_get_count(self):
frappe.local.request = frappe._dict()
frappe.local.request.method = "GET"
@ -1282,7 +1281,7 @@ class TestReportView(IntegrationTestCase):
child_filter_response = execute_cmd("frappe.desk.reportview.get_count")
current_value = frappe.db.sql(
# the below query is equivalent to the one in reportview.get_count
"select distinct count(distinct `tabDocType`.name) as total_count"
"select count(distinct `tabDocType`.name) as total_count"
" from `tabDocType` left join `tabDocField`"
" on (`tabDocField`.parenttype = 'DocType' and `tabDocField`.parent = `tabDocType`.name)"
" where `tabDocField`.`fieldtype` = 'Data'"