ON ERPNEXT AM GETTING THE ERROR ON ANY frappe.get_all FUNCTION THAT USES sum or count function

Example when i just go to the stock workspace i receive the following error

SQL functions are not allowed as strings in SELECT: sum(stock_value) stock_value. Use dict syntax like {'COUNT': '*'} instead.

This also happens on the Material Receipt, or while creating a stock entry and set stock entry type to material receipt.
then save it but on submit it will return the error

Invalid field format for SELECT: distinct target_fieldname as fieldname. Field names must be simple, backticked, table-qualified, aliased, or '*'.

This error i have try to fix them by changing the use of frappe.get_all and use a sql query builder but it’s not a fix that resolve the issue as it’s keeps popping up now and then.

Invalid field format for SELECT: max(period_end_date). Field names must be simple, backticked, table-qualified, aliased, or '*'.

am using the following version of the apps

ERPNext: v15.x.x-develop (develop)

Frappe Framework: v15.x.x-develop (996843f) (develop)

Bench version 5.25.1 and also it happens on bench version 5.25.9

I have tested the issue on version different versions and tested it on the latest version of frappe. version-16-beta but the issue is still there.

can anyone know how to solve the issue since the issue, i have this issue for about 2weeks now and even try solving it with AIs but with no luck.

I never feel stuck and demotivated in my career path like this :cry:. your help would be appreciated

Thanks in advance

v16 Query Builder & SQL Function Syntax CHnages

What Changed

The ORM methods frappe.db.get_value(), get_list(), and get_all() now use the Query Builder internally. This changes how SQL functions like Sum, Count, etc., must be used.

Migration Required

Old Syntax (v15):

frappe.qb.get_query("GP Task", fields=["sum(name) as count"])

New Syntax (v16):

frappe.qb.get_query("GP Task", fields=[{"SUM": "name", "as": "count"}])

Resources

Type Link
PR frappe#32381
Documentation Query Builder Migration Guide

Example PRs


3 Likes

Thanks for this, I can’t believe it, the things you mentioned and the links are such a helpful. Appreciate the help. I can’t thank you enough just know you save a brother. thank you.

1 Like