Try ERPNext Buy Support Partners Foundation Foundation Members

(Solved, well kind of) Error after upgrade from version 11 to 12 - Expression #n of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column

After upgrade, I am getting errors, in a few places, but mostly when trying to read an doc type (for example customer/order etc).

Examples of the actual error texts include

pymysql.err.InternalError: (1055, “Expression #2 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘_9ebf02b41d296e03.tabSales Invoice.modified’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”)

while the console just shows a 500 error code

13:13:49 web.1 | 127.0.0.1 - - [13/Oct/2019 13:13:49] “GET /api/method/frappe.desk.form.load.getdoc?doctype=Customer&name=GAUTENG+PROVINCE&=1570965155323 HTTP/1.1" 500 -
13:13:49 web.1 | INFO:werkzeug:127.0.0.1 - - [13/Oct/2019 13:13:49] "GET /api/method/frappe.desk.form.load.getdoc?doctype=Customer&name=GAUTENG+PROVINCE&
=1570965155323 HTTP/1.1” 500 -

I did the following prior :

  • Installed version 12 as suggested on the installation instructions
  • Copied data and files using “bench backup” from my current version 11 server
  • Restored the database and files using “bench restore” on my new installation
  • Ran “bench migrate” on my new installation
  • Restarted the bench, logged in, trying to navigate and getting the errors as described.

mysql --version
mysql Ver 15.1 Distrib 10.2.26-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

As it stand, the system is unusable due to the errors.

Some additional information from the error report

App Versions

{
“erpnext”: “12.1.6”,
“frappe”: “12.0.16”
}
Route

Form/Sales Order/SAL-ORD-2019-00074

Error Report

Traceback (most recent call last):
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line 34, in getdoc
run_onload(doc)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line 245, in run_onload
doc.run_method(“onload”)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 786, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 1056, in composer
return composed(self, method, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 1039, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 780, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/erpnext/erpnext/selling/doctype/customer/customer.py”, line 23, in onload
self.load_dashboard_info()
File “/erpnext_project_dir/frappe-bench/apps/erpnext/erpnext/selling/doctype/customer/customer.py”, line 26, in load_dashboard_info
info = get_dashboard_info(self.doctype, self.name, self.loyalty_program)
File “/erpnext_project_dir/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, line 508, in get_dashboard_info
fields=[“company”, “sum(grand_total) as grand_total”, “sum(base_grand_total) as base_grand_total”]
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/init.py”, line 1299, in get_all
return get_list(doctype, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/init.py”, line 1272, in get_list
return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 95, in execute
result = self.build_and_run()
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 129, in build_and_run
return frappe.db.sql(query, as_dict=not self.as_list, debug=self.debug, update=self.update)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/database/database.py”, line 171, in sql
self._cursor.execute(query)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 170, in execute
result = self._query(query)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 328, in _query
conn.query(q)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 732, in _read_query_result
result.read()
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 1075, in read
first_packet = self.connection._read_packet()
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 684, in _read_packet
packet.check_error()
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1055, “Expression #2 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘_9ebf02b41d296e03.tabSales Invoice.modified’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”)

Traceback (most recent call last):
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/handler.py”, line 56, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/init.py”, line 1036, in call
return fn(*args, **newargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line 34, in getdoc
run_onload(doc)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/desk/form/load.py”, line 245, in run_onload
doc.run_method(“onload”)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 786, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 1056, in composer
return composed(self, method, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 1039, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/document.py”, line 780, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/erpnext/erpnext/selling/doctype/customer/customer.py”, line 23, in onload
self.load_dashboard_info()
File “/erpnext_project_dir/frappe-bench/apps/erpnext/erpnext/selling/doctype/customer/customer.py”, line 26, in load_dashboard_info
info = get_dashboard_info(self.doctype, self.name, self.loyalty_program)
File “/erpnext_project_dir/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, line 508, in get_dashboard_info
fields=[“company”, “sum(grand_total) as grand_total”, “sum(base_grand_total) as base_grand_total”]
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/init.py”, line 1299, in get_all
return get_list(doctype, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/init.py”, line 1272, in get_list
return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 95, in execute
result = self.build_and_run()
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 129, in build_and_run
return frappe.db.sql(query, as_dict=not self.as_list, debug=self.debug, update=self.update)
File “/erpnext_project_dir/frappe-bench/apps/frappe/frappe/database/database.py”, line 171, in sql
self._cursor.execute(query)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 170, in execute
result = self._query(query)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/cursors.py”, line 328, in _query
conn.query(q)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 732, in _read_query_result
result.read()
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 1075, in read
first_packet = self.connection._read_packet()
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/connections.py”, line 684, in _read_packet
packet.check_error()
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/erpnext_project_dir/frappe-bench/env/lib/python3.6/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1055, “Expression #2 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘_9ebf02b41d296e03.tabSales Invoice.modified’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”)
Request Data
{
“type”: “GET”,
“args”: {
“doctype”: “Customer”,
“name”: “Eastern Cape Department of Health”
},
“headers”: {},
“error_handlers”: {},
“url”: “/api/method/frappe.desk.form.load.getdoc”
}
Response JSON

{}

I was able to solve this by logging in as mysql root and running

[mysql]> SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

This is only after for the current mysql instance. If I restart the mysql service I have to rerun the command.

References :
https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html