Payment Reconciliation error


Try to bench update – reset and get same error
Try to rest company transaction and get same error
Try to restore data base on other server with other ERPNext instance and get same error
Any other company on same server and same bench working without any errors

Error Traceback

### App Versions

{
“erpnext”: “13.49.12”,
“frappe”: “13.53.2”,
“persona”: “0.0.1”,
}

### Route

Form/Payment Reconciliation/Payment Reconciliation

### Trackeback

Syntax error in query:
select “Payment Entry” as reference_type, name as reference_name, posting_date,
remarks, unallocated_amount as amount, source_exchange_rate as exchange_rate, paid_from_account_currency as currency
from tabPayment Entry
where
paid_from = %s and party_type = %s and party = %s and payment_type = %s
and docstatus = 1 and unallocated_amount > 0 and company = ‘Trade Comany’
order by posting_date
Traceback (most recent call last):
File “apps/frappe/frappe/app.py”, line 66, in application
response = frappe.api.handle()
File “apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “apps/frappe/frappe/handler.py”, line 38, in handle
data = execute_cmd(cmd)
File “apps/frappe/frappe/handler.py”, line 76, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “apps/frappe/frappe/init.py”, line 1473, in call
return fn(*args, **newargs)
File “apps/frappe/frappe/handler.py”, line 275, in run_doc_method
response = doc.run_method(method)
File “apps/frappe/frappe/model/document.py”, line 943, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “apps/frappe/frappe/model/document.py”, line 1264, in composer
return composed(self, method, *args, **kwargs)
File “apps/frappe/frappe/model/document.py”, line 1246, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “apps/frappe/frappe/model/document.py”, line 940, in fn
return method_object(*args, **kwargs)
File “apps/erpnext/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py”, line 24, in get_unreconciled_entries
self.get_nonreconciled_payment_entries()
File “apps/erpnext/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py”, line 30, in get_nonreconciled_payment_entries
payment_entries = self.get_payment_entries()
File “apps/erpnext/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py”, line 56, in get_payment_entries
payment_entries = get_advance_payment_entries(
File “apps/erpnext/erpnext/controllers/accounts_controller.py”, line 2165, in get_advance_payment_entries
unallocated_payment_entries = frappe.db.sql(
File “apps/frappe/frappe/database/database.py”, line 187, in sql
self._cursor.execute(query, values)
File “env/lib/python3.8/site-packages/pymysql/cursors.py”, line 148, in execute
result = self._query(query)
File “env/lib/python3.8/site-packages/pymysql/cursors.py”, line 310, in _query
conn.query(q)
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 775, in _read_query_result
result.read()
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 1156, in read
first_packet = self.connection._read_packet()
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “env/lib/python3.8/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “env/lib/python3.8/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘s’ \n\t\t\t\torder by posting_date’ at line 6”)

### Request Data

{
“type”: “POST”,
“args”: {
“docs”: “{"name":"Payment Reconciliation","owner":"Administrator","creation":"2019-10-05 15:33:41.831633","modified":"2019-10-05 15:33:41.831633","modified_by":"Administrator","idx":"0","docstatus":0,"minimum_invoice_amount":0,"minimum_payment_amount":0,"maximum_invoice_amount":0,"maximum_payment_amount":0,"invoice_limit":0,"payment_limit":0,"doctype":"Payment Reconciliation","invoices":[],"payments":[],"allocation":[],"__last_sync_on":"2023-04-17T20:30:51.346Z","company":"Trade Comany","party_type":"Customer","party":"CI-02063","receivable_payable_account":"17101 - Customer - MT","__unsaved":1}”,
“method”: “get_unreconciled_entries”
},
“headers”: {},
“error_handlers”: {},
“url”: “/api/method/run_doc_method”
}

### Response Data

{
“exception”: “pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘s’ \n\t\t\t\torder by posting_date’ at line 6")”
}

we fix error by renaming company because company name was has( 's ) in last word