ProgrammingError: (1064, u"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 '%%%%''\n\t\t\t and coalesce(`tabWarehouse`.company, '')

Traceback (most recent call last):
  File "/opt/bench/erpnext/apps/frappe/frappe/app.py", line 55, in application
    try:
  File "/opt/bench/erpnext/apps/frappe/frappe/handler.py", line 20, in handle
    if cmd!='login':
  File "/opt/bench/erpnext/apps/frappe/frappe/handler.py", line 55, in execute_cmd
  File "/opt/bench/erpnext/apps/frappe/frappe/__init__.py", line 1007, in call
    return fn(*args, **newargs)
  File "/opt/bench/erpnext/apps/frappe/frappe/desk/search.py", line 53, in search_link
    search_widget(doctype, txt, query, searchfield=searchfield, page_length=page_length, filters=filters, ignore_user_permissions=ignore_user_permissions)
  File "/opt/bench/erpnext/apps/frappe/frappe/desk/search.py", line 77, in search_widget
    searchfield, start, page_length, filters, as_dict=as_dict)
  File "/opt/bench/erpnext/apps/frappe/frappe/__init__.py", line 1007, in call
    return fn(*args, **newargs)
  File "/opt/bench/erpnext/apps/erpnext/erpnext/controllers/queries.py", line 417, in warehouse_query
    return frappe.db.sql(query)
  File "/opt/bench/erpnext/apps/frappe/frappe/database/database.py", line 165, in sql
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 516, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 727, in _read_query_result
    result.read()
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1066, in read
    first_packet = self.connection._read_packet()
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 683, in _read_packet
    packet.check_error()
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
ProgrammingError: (1064, u"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 '%%%%''\n\t\t\t and coalesce(`tabWarehouse`.company, '') in ('', 'IOTech Surveillance' at line 7")

Anybody know how to fix this issue.

Share your query.

I am trying to create sales orders & invoices. When selecting delivery warehouse then this error comes up. I also tried to set the default warehouse on a item & when I created a sales order again then going down to change the delivery warehouse the default warehouse is set but as soon as you clear it 'n wait for the lookup this error comes up

Also tried now by firstly selecting the delivery warehouse before selecting the item. And no error appeared

It seems you are searching for a warehouse - what search term expression are you entering - maybe that contains an illegal metacharacter say a slash?

@surajshetty related to DB API fixes?

@Jaco_Hanekom Thanks for reporting the issue

Raised a pull request to fix this issue

Thanks,
Suraj

I also notice that I have stock in warehouses but can’t book it out as it says it requires the amount of items requested in the warehouse selected. On the item page it shows stock levels in warehouses and when I try to view stock balances in warehouses I get this error
Invalid CSV Format
File {u’file_name’: u’536986a57c’} not found
Unable to open attached file. Did you export it as CSV?

Any idea what this can be?